Advertisement
Barteks2x

Untitled

Sep 27th, 2016
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Groovy 7.87 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.    
  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()
  66.  
  67. minecraft {
  68.     version = "1.10.2-12.18.1.2092"
  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_20160918"
  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-RC2'){
  135.         exclude module: 'guava'
  136.     }
  137.     testCompile 'junit:junit:4.11'
  138.  
  139.     compile('org.spongepowered:mixin:0.5.11-SNAPSHOT') {
  140.         exclude module: 'launchwrapper'
  141.         exclude module: 'guava'
  142.         exclude module: 'gson'
  143.     }
  144.  
  145.     compile group: 'com.carrotsearch', name: 'hppc', version: '0.7.1'
  146. }
  147.  
  148. processResources
  149. {
  150.     // this will ensure that this task is redone when the versions change.
  151.     inputs.property "version", project.version
  152.     inputs.property "mcversion", project.minecraft.version
  153.  
  154.     // replace stuff in mcmod.info, nothing else
  155.     from(sourceSets.main.resources.srcDirs) {
  156.         include 'mcmod.info'
  157.                
  158.         // replace version and mcversion
  159.         expand 'version':project.version, 'mcversion':project.minecraft.version
  160.     }
  161.        
  162.     // copy everything else, thats not the mcmod.info
  163.     from(sourceSets.main.resources.srcDirs) {
  164.         exclude 'mcmod.info'
  165.     }
  166. }
  167.  
  168.  
  169. // License header formatting
  170. license {
  171.     ext.project = projectName
  172.     ext.year = inceptionYear
  173.     exclude "**/*.info"
  174.     exclude "**/*.json"
  175.     exclude "**/*.xml"
  176.     exclude "assets/*"
  177.     header file('HEADER.txt')
  178.     ignoreFailures false
  179.     strictCheck true
  180.     mapping {
  181.         java = 'SLASHSTAR_STYLE'
  182.     }
  183. }
  184.  
  185. jar {
  186.     manifest {
  187.         attributes 'FMLAT': 'cubicchunks_at.cfg'
  188.         attributes 'FMLCorePlugin': 'cubicchunks.asm.CoreModLoadingPlugin', 'FMLCorePluginContainsFMLMod': 'true'
  189.         attributes 'TweakClass': 'org.spongepowered.asm.launch.MixinTweaker'
  190.         attributes 'TweakOrder': '0'
  191.         attributes 'ForceLoadAsMod': 'true'
  192.     }
  193. }
  194.  
  195. idea {
  196.     module {
  197.         downloadJavadoc = true
  198.         downloadSources = true
  199.     }
  200. }
  201. //returns version string according to this: http://mcforge.readthedocs.org/en/latest/conventions/versioning/
  202. //format: MCVERSION-MAJORMOD.MAJORAPI.MINOR.PATCH(-final/rcX/betaX)
  203. //rcX and betaX are not implemented yet
  204. private String getModVersion(String describe, String branch) {
  205.     String branchSuffix = "";
  206.     if(!branch.equalsIgnoreCase("master")) {
  207.         //remove invalid filename characters
  208.         branchSuffix = "-" + branch.replaceAll("[^a-zA-Z0-9.-]", "_");
  209.     }
  210.     final String baseVersionRegex = "v[0-9]+\\.[0-9]+";
  211.     final String unknownVersion = String.format("%s-UNKNOWN_VERSION%s%s", mcVersion, versionSuffix, branchSuffix);
  212.     if (!describe.contains('-')) {
  213.         //is it the "vX.Y" format?
  214.         if (describe.matches(baseVersionRegex)) {
  215.             return String.format("%s-%s.0.0%s%s", mcVersion, describe, versionSuffix, branchSuffix);
  216.         }
  217.         logger.error("Git describe information: \"" + describe + "\" in unknown/incorrect format");
  218.         return unknownVersion;
  219.     }
  220.     //Describe format: vX.Y-build-hash
  221.     String[] parts = describe.split("-");
  222.     if (!parts[0].matches(baseVersionRegex)) {
  223.         logger.error("Git describe information: \"" + describe + "\" in unknown/incorrect format");
  224.         return unknownVersion;
  225.     }
  226.     if (!parts[1].matches("[0-9]+")) {
  227.         logger.error("Git describe information: \"" + describe + "\" in unknown/incorrect format");
  228.         return unknownVersion;
  229.     }
  230.     String mcVersion = mcVersion;
  231.     String modAndApiVersion = parts[0].substring(1);
  232.     //next we have commit-since-tag
  233.     int commitSinceTag;
  234.     commitSinceTag = Integer.parseInt(parts[1]);
  235.  
  236.     int minor;
  237.     int patch;
  238.     int minorFreeze = -1;
  239.     if (!(versionMinorFreeze == null || versionMinorFreeze.isEmpty())) {
  240.         minorFreeze = Integer.parseInt(versionMinorFreeze);
  241.     }
  242.     if (minorFreeze < 0) {
  243.         minor = commitSinceTag;
  244.         patch = 0;
  245.     } else {
  246.         minor = minorFreeze;
  247.         patch = commitSinceTag - minorFreeze;
  248.     }
  249.     String version = String.format("%s-%s.%d.%d%s%s", mcVersion, modAndApiVersion, minor, patch, versionSuffix, branchSuffix);
  250.     return version;
  251. }
  252. private String getModVersionAndWriteToFile() {
  253.     def git;
  254.     try {
  255.         git = org.ajoberstar.grgit.Grgit.open(file('.'))
  256.     } catch(org.eclipse.jgit.errors.RepositoryNotFoundException ex) {//TODO: Is there better way to check if the repository can be opened?
  257.         logger.error("Git repository not found! Version will be incorrect!");
  258.         return getModVersion("", "master");
  259.     }
  260.     String describe = git.describe();
  261.     String branch = git.getBranch().getCurrent().getName();
  262.     String version = getModVersion(describe, branch)
  263.     //write to file
  264.     File file = new File("VERSION");
  265.     PrintWriter pw = null;
  266.     try {
  267.         if(file.exists()) {
  268.             file.delete();
  269.         }
  270.         file.createNewFile();
  271.         pw = new PrintWriter(new FileOutputStream(file));
  272.         pw.println("VERSION=" + version);
  273.     } catch(IOException ex) {
  274.         ex.printStackTrace();
  275.     } finally {
  276.         if(pw != null) {
  277.             try{pw.close()}catch(IOException ex){}
  278.         }
  279.     }
  280.  
  281.     return version;
  282. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement