diff options
author | Johann Bernhardt <johann.bernhardt@tum.de> | 2021-11-07 16:36:54 +0100 |
---|---|---|
committer | Johann Bernhardt <johann.bernhardt@tum.de> | 2021-11-07 16:36:54 +0100 |
commit | cfbbcc87770da532f9bed9e3e4b824200970c34c (patch) | |
tree | aaedd3dd08329f3244b659db5e111d8c0a0cc92c /build.gradle | |
parent | 89ae9c98b8ace8bbd25d6fa2a0ade40e588aef38 (diff) | |
download | GT5-Unofficial-cfbbcc87770da532f9bed9e3e4b824200970c34c.tar.gz GT5-Unofficial-cfbbcc87770da532f9bed9e3e4b824200970c34c.tar.bz2 GT5-Unofficial-cfbbcc87770da532f9bed9e3e4b824200970c34c.zip |
Unify build script draft
Diffstat (limited to 'build.gradle')
-rw-r--r-- | build.gradle | 430 |
1 files changed, 313 insertions, 117 deletions
diff --git a/build.gradle b/build.gradle index f92e2a9a82..5c3a3f49a5 100644 --- a/build.gradle +++ b/build.gradle @@ -1,17 +1,27 @@ +/* +DO NOT CHANGE THIS FILE! + +Also, you may replace this file at any time if there is an update available. +Please check https://github.com/SinTh0r4s/ExampleMod1.7.10/blob/main/build.gradle for updates. + */ + + +import com.github.jengelman.gradle.plugins.shadow.tasks.ConfigureShadowRelocation +import java.util.concurrent.TimeUnit + buildscript { repositories { - mavenCentral() maven { - name = "gt" - url = "https://gregtech.overminddl1.com/" + name = "jitpack" + url = "https://jitpack.io" } maven { - name = "sonatype" - url = "https://oss.sonatype.org/content/repositories/snapshots/" + name = "forge" + url = "https://maven.minecraftforge.net" } maven { - name = "jitpack.io" - url = "https://jitpack.io" + name = "sonatype" + url = "https://oss.sonatype.org/content/repositories/snapshots/" } } dependencies { @@ -19,162 +29,348 @@ buildscript { } } +plugins { + id("org.ajoberstar.grgit") version("3.1.1") + id("com.github.johnrengelman.shadow") version("4.0.4") + id("com.palantir.git-version") version("0.12.3") +} + apply plugin: 'forge' apply plugin: 'idea' -apply plugin: 'java' -apply plugin: 'signing' -apply plugin: 'java-library' -file "build.properties" withReader { - def prop = new Properties() - prop.load(it) - ext.config = new ConfigSlurper().parse prop +idea { + module { + inheritOutputDirs = true + downloadJavadoc = true + downloadSources = true + } } -version = "${config.gt.version}" -group = "gregtech" -archivesBaseName = "gregtech" +configurations.all { + resolutionStrategy.cacheChangingModulesFor(0, TimeUnit.SECONDS) -compileJava { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 - options.encoding = "UTF-8" + // Make sure GregTech build won't time out + System.setProperty("org.gradle.internal.http.connectionTimeout", 120000 as String) + System.setProperty("org.gradle.internal.http.socketTimeout", 120000 as String) } +// Pulls version from git tag +version = minecraftVersion + "-" + gitVersion() +group = modGroup +archivesBaseName = modId + minecraft { - version = "${config.minecraft.version}-${config.forge.version}" + if(JavaVersion.current() != JavaVersion.VERSION_1_8) { + throw new GradleException("This project requires Java 8, but it's running on " + JavaVersion.current()) + } + + version = minecraftVersion + "-" + forgeVersion + "-" + minecraftVersion runDir = "run" + + if (replaceGradleTokenInFile) { + replaceIn replaceGradleTokenInFile + if(gradleTokenModId) { + replace gradleTokenModId, modId + } + if(gradleTokenModName) { + replace gradleTokenModName, modName + } + if(gradleTokenModName) { + replace gradleTokenVersion, versionDetails().lastTag + } + if(gradleTokenGroupName) { + replace gradleTokenGroupName, modGroup + } + } } -idea.module.inheritOutputDirs = true +apply from: 'repositories.gradle' + +configurations { + implementation.extendsFrom(shadowImplementation) +} repositories { - maven { - name = "gt" - url = "https://gregtech.overminddl1.com/" + if(usesMixins.toBoolean()) { + maven { + name = "sponge" + url = "https://repo.spongepowered.org/repository/maven-public" + } + maven { + url = "https://jitpack.io" + } } - maven { - name = "chickenbones" - url = "https://nexus.covers1624.net/repository/maven-hosted/" +} + +dependencies { + if(usesMixins.toBoolean()) { + annotationProcessor("org.ow2.asm:asm-debug-all:5.0.3") + annotationProcessor("com.google.guava:guava:24.1.1-jre") + annotationProcessor("com.google.code.gson:gson:2.8.6") + annotationProcessor("org.spongepowered:mixin:0.8-SNAPSHOT") + // using 0.8 to workaround a issue in 0.7 which fails mixin application + compile("org.spongepowered:mixin:0.7.11-SNAPSHOT") { + // Mixin includes a lot of dependencies that are too up-to-date + exclude module: "launchwrapper" + exclude module: "guava" + exclude module: "gson" + exclude module: "commons-io" + exclude module: "log4j-core" + } + compile("com.github.GTNewHorizons:SpongeMixins:1.3.3:dev") } - maven { - name = "ic2, forestry" - url = "http://downloads.gtnewhorizons.com/Mods_for_Jenkins/" +} + +apply from: 'dependencies.gradle' + +task relocateShadowJar(type: ConfigureShadowRelocation) { + target = tasks.shadowJar + prefix = modGroup + ".shadow" +} + +def mixinConfigJson = "mixins." + modId + ".json" +def mixingConfigRefMap = "mixins." + modId + ".refmap.json" +def refMap = "${tasks.compileJava.temporaryDir}" + File.separator + mixingConfigRefMap +def mixinSrg = "${tasks.reobf.temporaryDir}" + File.separator + "mixins.srg" + +task generateAssets { + if(usesMixins.toBoolean()) { + new File(projectDir.toString() + "/src/main/resources/", mixinConfigJson).text = """{ + "required": true, + "minVersion": "0.7.11", + "package": "${modGroup}.${mixinsPackage}", + "plugin": "${modGroup}.${mixinPlugin}", + "refmap": "${mixingConfigRefMap}", + "target": "@env(DEFAULT)", + "compatibilityLevel": "JAVA_8" +} + +""" } - maven { // EnderIO & EnderCore - name = 'tterrag Repo' - url = "http://maven.tterrag.com" +} + +shadowJar { + def manifestAttributes = [:] + if(containsMixinsAndOrCoreModOnly.toBoolean() == false) { + manifestAttributes += ["FMLCorePluginContainsFMLMod": true] } - maven { // TConstruct - name = 'DVS1 Maven FS' - url = 'http://dvs1.progwml6.com/files/maven' + + if(accessTransformersFile) { + manifestAttributes += ["FMLAT" : accessTransformersFile.toString()] } - maven { // AppleCore - url = "http://www.ryanliptak.com/maven/" + + if(coreModClass) { + manifestAttributes += ["FMLCorePlugin": modGroup + "." + coreModClass] } - maven { // GalacticGreg, YAMCore,.. - name = 'UsrvDE' - url = "http://jenkins.usrv.eu:8081/nexus/content/repositories/releases/" + + if(usesMixins.toBoolean()) { + from refMap + manifestAttributes += [ + "TweakClass" : "org.spongepowered.asm.launch.MixinTweaker", + "MixinConfigs" : mixinConfigJson, + "ForceLoadAsMod" : containsMixinsAndOrCoreModOnly.toBoolean() == false + ] } - ivy { - name = 'gtnh_download_source_stupid_underscore_typo' - artifactPattern("http://downloads.gtnewhorizons.com/Mods_for_Jenkins/[module]_[revision].[ext]") + manifest { + attributes(manifestAttributes) } - ivy { - name = 'gtnh_download_source' - artifactPattern("http://downloads.gtnewhorizons.com/Mods_for_Jenkins/[module]-[revision].[ext]") + + minimize() + configurations = [project.configurations.shadowImplementation] + dependsOn(relocateShadowJar) +} + +jar { + def manifestAttributes = [:] + if(containsMixinsAndOrCoreModOnly.toBoolean() == false) { + manifestAttributes += ["FMLCorePluginContainsFMLMod": true] } - maven { - name = "jitpack.io" - url = "https://jitpack.io" + + if(accessTransformersFile) { + manifestAttributes += ["FMLAT" : accessTransformersFile.toString()] } -} -dependencies { - //Hard dep to start (Without this, it wont compile nor start) - compile 'com.google.code.findbugs:jsr305:1.3.9' - compile "net.industrial-craft:industrialcraft-2:${config.ic2.version}:dev" - compile ("com.github.GTNewHorizons:StructureLib:${config.structurelib.version}:deobf") + if(coreModClass) { + manifestAttributes += ["FMLCorePlugin": modGroup + "." + coreModClass] + } + + if(usesMixins.toBoolean()) { + from refMap + manifestAttributes += [ + "TweakClass" : "org.spongepowered.asm.launch.MixinTweaker", + "MixinConfigs" : mixinConfigJson, + "ForceLoadAsMod" : containsMixinsAndOrCoreModOnly.toBoolean() == false + ] + } + manifest { + attributes(manifestAttributes) + } + + if(usesShadowedDependencies.toBoolean()) { + dependsOn(shadowJar) + enabled = false + } +} - //Hard dep to compile (Without this, it wont compile, not even as library) - api "appeng:appliedenergistics2:${config.ae2.version}:dev" - api "applecore:AppleCore:${config.applecore.version}:api" - api "codechicken:CodeChickenLib:${config.minecraft.version}-${config.codechickenlib.version}:dev" - api "codechicken:CodeChickenCore:${config.minecraft.version}-${config.codechickencore.version}:dev" - api "codechicken:NotEnoughItems:${config.minecraft.version}-${config.nei.version}:dev" - api "com.enderio.core:EnderCore:${config.enderiocore.version}:dev" - api("com.enderio:EnderIO:${config.enderio.version}:dev") { - transitive = false +reobf { + if(usesMixins.toBoolean()) { + addExtraSrgFile mixinSrg } +} - //Soft Depths (Without this, it wont compile, not needed as library) - compileOnly 'commons-io:commons-io:2.4' - compileOnly "eu.usrv:YAMCore:${config.minecraft.version}-${config.yamcore.version}:deobf" - compileOnly "tconstruct:TConstruct:${config.minecraft.version}-${config.tconstruct.version}:deobf" - compileOnly "codechicken:Translocator:${config.minecraft.version}-${config.translocators.version}:dev" - compileOnly "net.sengir.forestry:forestry_${config.minecraft.version}:${config.forestry.version}:dev" - compileOnly files("libs/Galacticraft-API-1.7-${config.gc.version}.jar") - compileOnly files("libs/GalacticraftCore-Dev-${config.gc.version}.jar") - compileOnly name: "Galacticraft-API", version: config.gc.version, ext: 'jar' - compileOnly name: "GalacticraftCore-Dev", version: config.gc.version, ext: 'jar' - compileOnly name: 'CoFHLib', version: config.cofhlib.version, ext: 'jar' - compileOnly name: 'Railcraft', version: config.railcraft.version, ext: 'jar' - compileOnly name: 'IC2NuclearControl', version: config.nc.version, ext: 'jar' +afterEvaluate { + if(usesMixins.toBoolean()) { + tasks.compileJava { + options.compilerArgs += [ + "-AreobfSrgFile=${tasks.reobf.srg}", + "-AoutSrgFile=${mixinSrg}", + "-AoutRefMapFile=${refMap}", + // Elan: from what I understand they are just some linter configs so you get some warning on how to properly code + "-XDenableSunApiLintControl", + "-XDignore.symbol.file" + ] + } + } } -processResources { - // this will ensure that this task is redone when the versions change. - inputs.property "version", project.version - inputs.property "mcversion", project.minecraft.version +runClient { + def arguments = [] - // replace stuff in mcmod.info, nothing else - from(sourceSets.main.resources.srcDirs) { - include 'mcmod.info' + if(usesMixins.toBoolean()) { + arguments += [ + "--mods=../build/libs/$modId-${version}.jar", + "--tweakClass org.spongepowered.asm.launch.MixinTweaker" + ] + } - // replace version and mcversion - expand 'version': project.version, 'mcversion': project.minecraft.version + if(developmentEnvironmentUserName) { + arguments += [ + "--username", + developmentEnvironmentUserName + ] } - // copy everything else, that's not the mcmod.info - from(sourceSets.main.resources.srcDirs) { - exclude 'mcmod.info' + args(arguments) +} + +runServer { + def arguments = [] + + if(usesMixins.toBoolean()) { + arguments += [ + "--mods=../build/libs/$modId-${version}.jar", + "--tweakClass org.spongepowered.asm.launch.MixinTweaker" + ] } - exclude '**/Thumbs.db' + + args(arguments) } -task sourceJar(type: Jar) { - from sourceSets.main.allSource - archiveClassifier.set('sources') +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 "minecraftVersion": project.minecraft.version, + "modVersion": versionDetails().lastTag, + "modId": modId, + "modName": modName + } + + // copy everything else, thats not the mcmod.info + from(sourceSets.main.resources.srcDirs) { + exclude 'mcmod.info' + } + } + +task sourcesJar(type: Jar) { + from (sourceSets.main.allJava) + from (file("$projectDir/LICENSE")) + getArchiveClassifier().set('sources') + + def manifestAttributes = [:] + if(containsMixinsAndOrCoreModOnly.toBoolean() == false) { + manifestAttributes += ["FMLCorePluginContainsFMLMod": true] + } + + if(accessTransformersFile) { + manifestAttributes += ["FMLAT" : accessTransformersFile.toString()] + } + + if(coreModClass) { + manifestAttributes += ["FMLCorePlugin": modGroup + "." + coreModClass] + } + + if(usesMixins.toBoolean()) { + from refMap + manifestAttributes += [ + "TweakClass" : "org.spongepowered.asm.launch.MixinTweaker", + "MixinConfigs" : mixinConfigJson, + "ForceLoadAsMod" : containsMixinsAndOrCoreModOnly.toBoolean() == false + ] + } + manifest { + attributes(manifestAttributes) + } } task devJar(type: Jar) { from sourceSets.main.output - archiveClassifier.set('dev') + getArchiveClassifier().set("dev") + + def manifestAttributes = [:] + if(containsMixinsAndOrCoreModOnly.toBoolean() == false) { + manifestAttributes += ["FMLCorePluginContainsFMLMod": true] + } + + if(accessTransformersFile) { + manifestAttributes += ["FMLAT" : accessTransformersFile.toString()] + } + + if(coreModClass) { + manifestAttributes += ["FMLCorePlugin": modGroup + "." + coreModClass] + } + + if(usesMixins.toBoolean()) { + from refMap + manifestAttributes += [ + "TweakClass" : "org.spongepowered.asm.launch.MixinTweaker", + "MixinConfigs" : mixinConfigJson, + "ForceLoadAsMod" : containsMixinsAndOrCoreModOnly.toBoolean() == false + ] + } + manifest { + attributes(manifestAttributes) + } } task apiJar(type: Jar) { - from sourceSets.main.allSource - include("gregtech/api/**") - archiveClassifier.set('api') + from (sourceSets.main.allJava) { + include modGroup.toString().replaceAll("\\.", "/") + "/" + apiPackage.toString() + '/**' + } + + from (sourceSets.main.output) { + include modGroup.toString().replaceAll("\\.", "/") + "/" + apiPackage.toString() + '/**' + } + + from (sourceSets.main.resources.srcDirs) { + include("LICENSE") + } + + getArchiveClassifier().set('api') } + artifacts { - archives(devJar) - archives(sourceJar) - archives(apiJar) -} - -task signJar(dependsOn: 'reobf') { - doLast { - ant.signjar( - destDir: jar.getDestinationDirectory(), - jar: jar.getArchivePath(), - alias: findProperty('keyStoreAlias') ?: '', - keystore: findProperty('keyStore') ?: '', - storepass: findProperty('keyStorePass') ?: '', - digestalg: findProperty('signDigestAlg') ?: '', - tsaurl: findProperty('signTSAurl') ?: '', - verbose: true - ) + archives sourcesJar + archives devJar + if(apiPackage) { + archives apiJar } } |