Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Gradle repositories and dependencies
- buildscript
- {
- repositories {
- mavenCentral()
- jcenter()
- maven {
- name = "forge"
- url = "http://files.minecraftforge.net/maven"
- }
- maven {
- name = 'sponge'
- url = 'http://repo.spongepowered.org/maven'
- }
- }
- dependencies {
- classpath 'net.minecraftforge.gradle:ForgeGradle:2.2-SNAPSHOT'
- classpath 'org.ajoberstar:grgit:1.4.+'
- classpath 'org.spongepowered:mixingradle:0.3-SNAPSHOT'
- classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.3'
- }
- }
- plugins {
- id "java"
- id "com.github.hierynomus.license" version "0.11.0"
- id "eclipse"
- id "idea"
- id 'com.github.johnrengelman.shadow' version '1.2.3'
- }
- apply plugin: 'net.minecraftforge.gradle.forge'
- apply plugin: 'org.spongepowered.mixin'
- idea { module { inheritOutputDirs = true } }
- defaultTasks 'licenseFormat', 'build'
- // Minimum version of Java required
- sourceCompatibility = '1.8'
- targetCompatibility = '1.8'
- mixin {
- add sourceSets.main, "cubicchunks.mixins.refmap.json"
- //add sourceSets.main,
- }
- repositories {
- mavenCentral()
- maven {
- name = 'sponge'
- url = 'http://repo.spongepowered.org/maven'
- }
- }
- ext {
- //used for license header
- projectName = 'Cubic Chunks Mod'
- inceptionYear = '2015'
- }
- group = "cubichunks"
- archivesBaseName = "CubicChunks"
- version = getModVersionAndWriteToFile()
- minecraft {
- version = "1.10.2-12.18.1.2092"
- runDir = "run"
- // the mappings can be changed at any time, and must be in the following format.
- // snapshot_YYYYMMDD snapshot are built nightly.
- // stable_# stables are built at the discretion of the MCP team.
- // Use non-default mappings at your own risk. they may not always work.
- // simply re-run your setup task after changing the mappings to update your workspace.
- mappings = "snapshot_20160918"
- // makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable.
- replace "@@VERSION@@", project.version
- replaceIn "cubicchunks/CubicChunks.java"
- }
- shadowJar {
- //MapDB stuff
- relocate 'org.mapdb', 'cubicchunks.org.mappdb'
- relocate 'kotlin', 'cubicchunks.org.mappdb.com.google'
- relocate 'net.jcip', 'cubicchunks.org.mappdb.net.jcip'
- relocate 'org.eclipse.collections', 'cubicchunks.org.mappdb.org.eclipse.collections'
- relocate 'net.jpountz', 'cubicchunks.org.mappdb.net.jpountz'
- //MapDB natives. Will it work?
- relocate 'win32', 'cubicchunks.org.mappdb.win32'
- relocate 'linux', 'cubicchunks.org.mappdb.linux'
- relocate 'darwin', 'cubicchunks.org.mappdb.darwin'
- relocate 'com.flowpowered', 'cubicchunks.com.flowpowered'
- /*
- Mixin shouldn't be relocated. Mixin dependencies:
- org.spongepowered:mixin:0.5.5-SNAPSHOT
- +--- org.slf4j:slf4j-api:1.7.7
- +--- commons-codec:commons-codec:1.9
- +--- org.ow2.asm:asm-commons:5.0.3
- | \--- org.ow2.asm:asm-tree:5.0.3
- | \--- org.ow2.asm:asm:5.0.3
- +--- commons-io:commons-io:2.4
- \--- com.googlecode.jarjar:jarjar:1.1
- */
- classifier = ''
- }
- reobf {
- shadowJar { mappingType = 'SEARGE' }
- }
- tasks.build.dependsOn reobfShadowJar
- jar {
- exclude 'LICENSE.txt'
- }
- // Project repositories
- repositories {
- mavenCentral()
- maven
- {
- name 'sonatype'
- url 'https://oss.sonatype.org/content/groups/public/'
- }
- }
- dependencies {
- compile 'com.flowpowered:flow-noise:1.0.1-SNAPSHOT'
- compile('org.mapdb:mapdb:3.0.0-RC2'){
- exclude module: 'guava'
- }
- testCompile 'junit:junit:4.11'
- compile('org.spongepowered:mixin:0.5.11-SNAPSHOT') {
- exclude module: 'launchwrapper'
- exclude module: 'guava'
- exclude module: 'gson'
- }
- compile group: 'com.carrotsearch', name: 'hppc', version: '0.7.1'
- }
- processResources
- {
- // this will ensure that this task is redone when the versions change.
- inputs.property "version", project.version
- inputs.property "mcversion", project.minecraft.version
- // replace stuff in mcmod.info, nothing else
- from(sourceSets.main.resources.srcDirs) {
- include 'mcmod.info'
- // replace version and mcversion
- expand 'version':project.version, 'mcversion':project.minecraft.version
- }
- // copy everything else, thats not the mcmod.info
- from(sourceSets.main.resources.srcDirs) {
- exclude 'mcmod.info'
- }
- }
- // License header formatting
- license {
- ext.project = projectName
- ext.year = inceptionYear
- exclude "**/*.info"
- exclude "**/*.json"
- exclude "**/*.xml"
- exclude "assets/*"
- header file('HEADER.txt')
- ignoreFailures false
- strictCheck true
- mapping {
- java = 'SLASHSTAR_STYLE'
- }
- }
- jar {
- manifest {
- attributes 'FMLAT': 'cubicchunks_at.cfg'
- attributes 'FMLCorePlugin': 'cubicchunks.asm.CoreModLoadingPlugin', 'FMLCorePluginContainsFMLMod': 'true'
- attributes 'TweakClass': 'org.spongepowered.asm.launch.MixinTweaker'
- attributes 'TweakOrder': '0'
- attributes 'ForceLoadAsMod': 'true'
- }
- }
- idea {
- module {
- downloadJavadoc = true
- downloadSources = true
- }
- }
- //returns version string according to this: http://mcforge.readthedocs.org/en/latest/conventions/versioning/
- //format: MCVERSION-MAJORMOD.MAJORAPI.MINOR.PATCH(-final/rcX/betaX)
- //rcX and betaX are not implemented yet
- private String getModVersion(String describe, String branch) {
- String branchSuffix = "";
- if(!branch.equalsIgnoreCase("master")) {
- //remove invalid filename characters
- branchSuffix = "-" + branch.replaceAll("[^a-zA-Z0-9.-]", "_");
- }
- final String baseVersionRegex = "v[0-9]+\\.[0-9]+";
- final String unknownVersion = String.format("%s-UNKNOWN_VERSION%s%s", mcVersion, versionSuffix, branchSuffix);
- if (!describe.contains('-')) {
- //is it the "vX.Y" format?
- if (describe.matches(baseVersionRegex)) {
- return String.format("%s-%s.0.0%s%s", mcVersion, describe, versionSuffix, branchSuffix);
- }
- logger.error("Git describe information: \"" + describe + "\" in unknown/incorrect format");
- return unknownVersion;
- }
- //Describe format: vX.Y-build-hash
- String[] parts = describe.split("-");
- if (!parts[0].matches(baseVersionRegex)) {
- logger.error("Git describe information: \"" + describe + "\" in unknown/incorrect format");
- return unknownVersion;
- }
- if (!parts[1].matches("[0-9]+")) {
- logger.error("Git describe information: \"" + describe + "\" in unknown/incorrect format");
- return unknownVersion;
- }
- String mcVersion = mcVersion;
- String modAndApiVersion = parts[0].substring(1);
- //next we have commit-since-tag
- int commitSinceTag;
- commitSinceTag = Integer.parseInt(parts[1]);
- int minor;
- int patch;
- int minorFreeze = -1;
- if (!(versionMinorFreeze == null || versionMinorFreeze.isEmpty())) {
- minorFreeze = Integer.parseInt(versionMinorFreeze);
- }
- if (minorFreeze < 0) {
- minor = commitSinceTag;
- patch = 0;
- } else {
- minor = minorFreeze;
- patch = commitSinceTag - minorFreeze;
- }
- String version = String.format("%s-%s.%d.%d%s%s", mcVersion, modAndApiVersion, minor, patch, versionSuffix, branchSuffix);
- return version;
- }
- private String getModVersionAndWriteToFile() {
- def git;
- try {
- git = org.ajoberstar.grgit.Grgit.open(file('.'))
- } catch(org.eclipse.jgit.errors.RepositoryNotFoundException ex) {//TODO: Is there better way to check if the repository can be opened?
- logger.error("Git repository not found! Version will be incorrect!");
- return getModVersion("", "master");
- }
- String describe = git.describe();
- String branch = git.getBranch().getCurrent().getName();
- String version = getModVersion(describe, branch)
- //write to file
- File file = new File("VERSION");
- PrintWriter pw = null;
- try {
- if(file.exists()) {
- file.delete();
- }
- file.createNewFile();
- pw = new PrintWriter(new FileOutputStream(file));
- pw.println("VERSION=" + version);
- } catch(IOException ex) {
- ex.printStackTrace();
- } finally {
- if(pw != null) {
- try{pw.close()}catch(IOException ex){}
- }
- }
- return version;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement