Advertisement
Barteks2x

Untitled

Jun 22nd, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Groovy 7.40 KB | None | 0 0
  1. // Gradle repositories and dependencies
  2. buildscript
  3. {
  4.     repositories {
  5.         mavenCentral()
  6.         jcenter()
  7.         maven {
  8.             name = "forge"
  9.             url = "http://files.minecraftforge.net/maven"
  10.         }
  11.         maven {
  12.             name = 'sponge'
  13.             url = 'http://repo.spongepowered.org/maven'
  14.         }
  15.     }
  16.     dependencies {
  17.         classpath 'net.minecraftforge.gradle:ForgeGradle:2.2-SNAPSHOT'
  18.         classpath 'org.ajoberstar:grgit:1.4.+'
  19.         classpath 'org.spongepowered:mixingradle:0.3-SNAPSHOT'
  20.         classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.3'
  21.     }
  22. }
  23.  
  24. plugins {
  25.     id "java"
  26.     id "com.github.hierynomus.license" version "0.11.0"
  27.     id "eclipse"
  28.     id "idea"
  29.     id 'com.github.johnrengelman.shadow' version '1.2.3'
  30. }
  31. apply plugin: 'net.minecraftforge.gradle.forge'
  32. apply plugin: 'org.spongepowered.mixin'
  33.  
  34. idea { module { inheritOutputDirs = true } }
  35.  
  36. defaultTasks 'licenseFormat', 'build'
  37.  
  38. // Minimum version of Java required
  39. sourceCompatibility = '1.8'
  40. targetCompatibility = '1.8'
  41.  
  42. mixin {
  43.     add sourceSets.main, "cubicchunks.mixins.refmap.json"
  44.     //add sourceSets.main,
  45. }
  46.  
  47. repositories {
  48.     mavenCentral()
  49.     maven {
  50.         name = 'sponge'
  51.         url = 'http://repo.spongepowered.org/maven'
  52.     }
  53. }
  54.  
  55. ext {
  56.     git = org.ajoberstar.grgit.Grgit.open(file('.'))
  57.  
  58.     //used for license header
  59.     projectName = 'Cubic Chunks Mod'
  60.     inceptionYear = '2015'
  61. }
  62.  
  63. group = "cubichunks"
  64. archivesBaseName = "CubicChunks"
  65. version = getModVersionAndWriteToFile("${git.describe()}", "${git.branch.getCurrent().getName()}")
  66.  
  67. minecraft {
  68.     version = "1.9.4-12.17.0.1969"
  69.     runDir = "run"
  70.  
  71.     // the mappings can be changed at any time, and must be in the following format.
  72.     // snapshot_YYYYMMDD   snapshot are built nightly.
  73.     // stable_#            stables are built at the discretion of the MCP team.
  74.     // Use non-default mappings at your own risk. they may not always work.
  75.     // simply re-run your setup task after changing the mappings to update your workspace.
  76.     mappings = "snapshot_20160622"
  77.     // makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable.
  78.  
  79.     replace "@@VERSION@@", project.version
  80.     replaceIn "cubicchunks/CubicChunks.java"
  81.  
  82. }
  83.  
  84. shadowJar {
  85.     //MapDB stuff
  86.     relocate 'org.mapdb', 'cubicchunks.org.mappdb'
  87.     relocate 'kotlin', 'cubicchunks.org.mappdb.com.google'
  88.     relocate 'net.jcip', 'cubicchunks.org.mappdb.net.jcip'
  89.     relocate 'org.eclipse.collections', 'cubicchunks.org.mappdb.org.eclipse.collections'
  90.     relocate 'net.jpountz', 'cubicchunks.org.mappdb.net.jpountz'
  91.  
  92.     //MapDB natives. Will it work?
  93.     relocate 'win32', 'cubicchunks.org.mappdb.win32'
  94.     relocate 'linux', 'cubicchunks.org.mappdb.linux'
  95.     relocate 'darwin', 'cubicchunks.org.mappdb.darwin'
  96.  
  97.     relocate 'com.flowpowered', 'cubicchunks.com.flowpowered'
  98.     /*
  99.     Mixin shouldn't be relocated. Mixin dependencies:
  100.      org.spongepowered:mixin:0.5.5-SNAPSHOT
  101.      +--- org.slf4j:slf4j-api:1.7.7
  102.      +--- commons-codec:commons-codec:1.9
  103.      +--- org.ow2.asm:asm-commons:5.0.3
  104.      |    \--- org.ow2.asm:asm-tree:5.0.3
  105.      |         \--- org.ow2.asm:asm:5.0.3
  106.      +--- commons-io:commons-io:2.4
  107.      \--- com.googlecode.jarjar:jarjar:1.1
  108.      */
  109.     classifier = ''
  110. }
  111.  
  112. reobf {
  113.     shadowJar { mappingType = 'SEARGE' }
  114. }
  115.  
  116. tasks.build.dependsOn reobfShadowJar
  117.  
  118. jar {
  119.     exclude 'LICENSE.txt'
  120. }
  121.  
  122. // Project repositories
  123. repositories {
  124.     mavenCentral()
  125.     maven
  126.     {
  127.         name 'sonatype'
  128.         url 'https://oss.sonatype.org/content/groups/public/'
  129.     }
  130. }
  131.  
  132. dependencies {
  133.     compile 'com.flowpowered:flow-noise:1.0.1-SNAPSHOT'
  134.     compile('org.mapdb:mapdb:3.0.0-RC1'){
  135.         exclude module: 'guava'
  136.     }
  137.     testCompile 'junit:junit:4.11'
  138.  
  139.     compile('org.spongepowered:mixin:0.5.6-SNAPSHOT') {
  140.         exclude module: 'launchwrapper'
  141.         exclude module: 'guava'
  142.         exclude module: 'gson'
  143.     }
  144. }
  145.  
  146. processResources
  147. {
  148.     // this will ensure that this task is redone when the versions change.
  149.     inputs.property "version", project.version
  150.     inputs.property "mcversion", project.minecraft.version
  151.  
  152.     // replace stuff in mcmod.info, nothing else
  153.     from(sourceSets.main.resources.srcDirs) {
  154.         include 'mcmod.info'
  155.                
  156.         // replace version and mcversion
  157.         expand 'version':project.version, 'mcversion':project.minecraft.version
  158.     }
  159.        
  160.     // copy everything else, thats not the mcmod.info
  161.     from(sourceSets.main.resources.srcDirs) {
  162.         exclude 'mcmod.info'
  163.     }
  164. }
  165.  
  166.  
  167. // License header formatting
  168. license {
  169.     ext.project = projectName
  170.     ext.year = inceptionYear
  171.     exclude "**/*.info"
  172.     exclude "**/*.json"
  173.     exclude "**/*.xml"
  174.     exclude "assets/*"
  175.     header file('HEADER.txt')
  176.     ignoreFailures false
  177.     strictCheck true
  178.     mapping {
  179.         java = 'SLASHSTAR_STYLE'
  180.     }
  181. }
  182.  
  183. jar {
  184.     manifest {
  185.         attributes 'FMLAT': 'cubicchunks_at.cfg'
  186.         attributes 'FMLCorePlugin': 'cubicchunks.asm.CoreModLoadingPlugin', 'FMLCorePluginContainsFMLMod': 'true'
  187.         attributes 'TweakClass': 'org.spongepowered.asm.launch.MixinTweaker'
  188.         attributes 'TweakOrder': '0'
  189.         attributes 'ForceLoadAsMod': 'true'
  190.         attributes 'MixinCompatibilityLevel': 'JAVA_8'
  191.     }
  192. }
  193.  
  194. //returns version string according to this: http://mcforge.readthedocs.org/en/latest/conventions/versioning/
  195. //format: MCVERSION-MAJORMOD.MAJORAPI.MINOR.PATCH(-final/rcX/betaX)
  196. //rcX and betaX are not implemented yet
  197. private String getModVersion(String describe, String branch) {
  198.     String branchSuffix = "";
  199.     if(!branch.equalsIgnoreCase("master")) {
  200.         //remove invalid filename characters
  201.         branchSuffix = "-" + branch.replaceAll("[^a-zA-Z0-9.-]", "_");
  202.     }
  203.     final String baseVersionRegex = "v[0-9]+\\.[0-9]+";
  204.     final String unknownVersion = String.format("%s-UNKNOWN_VERSION%s%s", mcVersion, versionSuffix, branchSuffix);
  205.     if (!describe.contains('-')) {
  206.         //is it the "vX.Y" format?
  207.         if (describe.matches(baseVersionRegex)) {
  208.             return String.format("%s-%s.0.0%s%s", mcVersion, describe, versionSuffix, branchSuffix);
  209.         }
  210.         return unknownVersion;
  211.     }
  212.     //Describe format: vX.Y-build-hash
  213.     String[] parts = describe.split("-");
  214.     if (!parts[0].matches(baseVersionRegex)) {
  215.         return unknownVersion;
  216.     }
  217.     if (!parts[1].matches("[0-9]+")) {
  218.         return unknownVersion;
  219.     }
  220.     String mcVersion = mcVersion;
  221.     String modAndApiVersion = parts[0].substring(1);
  222.     //next we have commit-since-tag
  223.     int commitSinceTag;
  224.     try {
  225.         commitSinceTag = Integer.parseInt(parts[1]);
  226.     } catch (NumberFormatException ex) {
  227.         ex.printStackTrace();
  228.         return unknownVersion;
  229.     }
  230.  
  231.     int minor;
  232.     int patch;
  233.     int minorFreeze = -1;
  234.     if (!(versionMinorFreeze == null || versionMinorFreeze.isEmpty())) {
  235.         try {
  236.             minorFreeze = Integer.parseInt(versionMinorFreeze);
  237.         } catch (NumberFormatException ex) {
  238.             ex.printStackTrace();
  239.         }
  240.     }
  241.     if (minorFreeze < 0) {
  242.         minor = commitSinceTag;
  243.         patch = 0;
  244.     } else {
  245.         minor = minorFreeze;
  246.         patch = commitSinceTag - minorFreeze;
  247.     }
  248.     String version = String.format("%s-%s.%d.%d%s%s", mcVersion, modAndApiVersion, minor, patch, versionSuffix, branchSuffix);
  249.     return version;
  250. }
  251. private String getModVersionAndWriteToFile(String describe, String branch) {
  252.     String version = getModVersion(describe, branch)
  253.     //write to file
  254.     File file = new File("VERSION");
  255.     PrintWriter pw = null;
  256.     try {
  257.         if(file.exists()) {
  258.             file.delete();
  259.         }
  260.         file.createNewFile();
  261.         pw = new PrintWriter(new FileOutputStream(file));
  262.         pw.println("VERSION=" + version);
  263.     } catch(IOException ex) {
  264.         ex.printStackTrace();
  265.     } finally {
  266.         if(pw != null) {
  267.             try{pw.close()}catch(IOException ex){}
  268.         }
  269.     }
  270.  
  271.     return version;
  272. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement