|
| 1 | +// specify repositories and dependencies |
| 2 | +buildscript { |
| 3 | + repositories { |
| 4 | + jcenter() |
| 5 | + maven { |
| 6 | + name = "forge" |
| 7 | + url = "http://files.minecraftforge.net/maven" |
| 8 | + } |
| 9 | + } |
| 10 | + dependencies { |
| 11 | + classpath "net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT" |
| 12 | + } |
| 13 | +} |
| 14 | + |
| 15 | +// apply plugins |
| 16 | +apply plugin: project.mcVersion.equals("1.7.10") ? "forge" : "net.minecraftforge.gradle.forge" |
| 17 | + |
| 18 | +// set java version |
| 19 | +sourceCompatibility = project.javaVersion |
| 20 | +targetCompatibility = project.javaVersion |
| 21 | + |
| 22 | +version=getVersionFromJava(file("src/main/java/" + project.modClass)) |
| 23 | +group=project.name.toLowerCase() |
| 24 | +archivesBaseName = project.name + "-" + project.mcVersion |
| 25 | + |
| 26 | +// source directories |
| 27 | +sourceSets { |
| 28 | + main { |
| 29 | + java { srcDirs = ["$projectDir/src/main/java"] } |
| 30 | + resources { srcDirs = ["$projectDir/src/main/resources"] } |
| 31 | + } |
| 32 | +} |
| 33 | + |
| 34 | +jar { |
| 35 | + manifest { |
| 36 | + attributes 'FMLCorePlugin': 'coolsquid.eventtimer.asm.EventTimerPlugin' |
| 37 | + attributes 'FMLCorePluginContainsFMLMod': 'true' |
| 38 | + } |
| 39 | +} |
| 40 | + |
| 41 | +// set forge version and mappings |
| 42 | +minecraft { |
| 43 | + version = project.mcVersion + "-" + project.forgeVersion |
| 44 | + runDir = "run" |
| 45 | + mappings = project.mappings |
| 46 | +} |
| 47 | + |
| 48 | +repositories { |
| 49 | + maven { |
| 50 | + url "http://www.ryanliptak.com/maven/" |
| 51 | + } |
| 52 | +} |
| 53 | +// include all files in /libs as dependencies |
| 54 | +dependencies { |
| 55 | + compile fileTree(dir: "libs", include: "*.jar,*.zip") |
| 56 | + deobfCompile "applecore:AppleCore:1.12.2-3.2.0+335.2dbab:api" |
| 57 | +} |
| 58 | + |
| 59 | +// update mcmod.info |
| 60 | +processResources |
| 61 | +{ |
| 62 | + // this will ensure that this task is redone when the versions change. |
| 63 | + inputs.property "version", project.version |
| 64 | + inputs.property "mcversion", project.mcVersion |
| 65 | + |
| 66 | + // replace stuff in mcmod.info, nothing else |
| 67 | + from(sourceSets.main.resources) { |
| 68 | + include "mcmod.info" |
| 69 | + |
| 70 | + // replace version and mcversion |
| 71 | + expand "version":project.version, "mcversion":project.minecraft.version |
| 72 | + } |
| 73 | + |
| 74 | + // copy everything else, thats not the mcmod.info |
| 75 | + from(sourceSets.main.resources) { |
| 76 | + exclude "mcmod.info" |
| 77 | + } |
| 78 | +} |
| 79 | + |
| 80 | +task sourcesJar(type: Jar, dependsOn: classes) { |
| 81 | + classifier = "sources" |
| 82 | + from sourceSets.main.java |
| 83 | +} |
| 84 | + |
| 85 | +task devJar(type: Jar) { |
| 86 | + from sourceSets.main.output |
| 87 | + classifier = "dev" |
| 88 | +} |
| 89 | + |
| 90 | +// make the dev and source jars |
| 91 | +artifacts { |
| 92 | + if (Boolean.parseBoolean(project.makeSourceJar)) { |
| 93 | + archives sourcesJar |
| 94 | + } |
| 95 | + if (Boolean.parseBoolean(project.makeDevJar)) { |
| 96 | + archives devJar |
| 97 | + } |
| 98 | +} |
| 99 | + |
| 100 | +String getVersionFromJava(File file) { |
| 101 | + |
| 102 | + String release = "0"; |
| 103 | + String update = "0"; |
| 104 | + String patch = "0"; |
| 105 | + |
| 106 | + String build = System.getenv("BUILD_NUMBER") ? System.getenv("BUILD_NUMBER") : "0"; |
| 107 | + def outfile = ""; |
| 108 | + def ln = System.getProperty("line.separator") |
| 109 | + |
| 110 | + String prefix = "public static final String VERSION = \""; |
| 111 | + file.eachLine { |
| 112 | + String s -> |
| 113 | + |
| 114 | + String v = s.trim(); |
| 115 | + |
| 116 | + if (v.startsWith(prefix)) { |
| 117 | + |
| 118 | + v = v.substring(prefix.length(), v.length() - 2); |
| 119 | + String[] pts = v.split("\\."); |
| 120 | + |
| 121 | + release = pts[0]; |
| 122 | + update = pts[1]; |
| 123 | + patch = pts[2]; |
| 124 | + s = s.replaceAll(".0\";", ".${build}\";"); |
| 125 | + } |
| 126 | + |
| 127 | + outfile += (s + ln); |
| 128 | + } |
| 129 | + |
| 130 | + file.write(outfile); |
| 131 | + |
| 132 | + return "$release.$update.$patch"; |
| 133 | +} |
0 commit comments