From 1a4e5b27d0c383194c3ae89f92443b3a5c24cc31 Mon Sep 17 00:00:00 2001 From: Kitteh6660 Date: Fri, 7 Jun 2024 16:57:32 -0400 Subject: [PATCH] Upgrade Gradle configurations Modernize Gradle setup and allow working up to JDK 22. --- build.gradle | 255 +++++++++-------------- gradle.properties | 24 ++- gradle/wrapper/gradle-wrapper.properties | 2 +- projects.gradle | 190 ----------------- settings.gradle | 12 ++ 5 files changed, 128 insertions(+), 355 deletions(-) delete mode 100644 projects.gradle diff --git a/build.gradle b/build.gradle index 1f5de95427..1494a133e5 100644 --- a/build.gradle +++ b/build.gradle @@ -1,176 +1,107 @@ -buildscript { - repositories { - jcenter() - maven { - name = 'forge' - url = 'http://files.minecraftforge.net/maven' - } - maven { - url 'https://plugins.gradle.org/m2/' - } - } - dependencies { - classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT' - } +plugins { + id 'idea' + id 'eclipse' + id 'maven-publish' + id 'net.minecraftforge.gradle' version '[6.0,6.2)' + id 'org.spongepowered.mixin' version '0.7-SNAPSHOT' } - -//Returns whether the private keystore for signing is available and if the jar should be signed -project.ext.canJarBeSigned = { - return getVariable('blKeyStore') != null && (!isDeploymentEnv || isDeploymentRelease) +base { + archivesBaseName = project.archives_base_name // "${rootProject.archives_base_name}-${project.name}" } - -//Returns the public fingerprint, may be empty ("") -project.ext.getProjectFingerprint = { - if(canJarBeSigned()) { - return getVariable('blKeyStoreFingerprint').replaceAll(':', '').toLowerCase() - } - return '' +mixin { + // add(sourceSets.main, "mixins.${rootProject.mod_id}.refmap.json") + // config(mixins.${rootProject.mod_id}.json) +} +minecraft { + mappings channel: 'official', version: rootProject.minecraft_version + copyIdeResources = true //Calls processResources when in dev + accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg') + runs { + client { + workingDirectory project.file('run') + ideaModule "${rootProject.name}.${project.name}.main" + taskName 'runClient' + property 'mixin.env.remapRefMap', 'true' + property 'mixin.env.refMapRemappingFile', "${projectDir}/build/createSrgToMcp/output.srg" + arg "-mixin.config=" + "betweenlands.mixins.json" + mods { + modClientRun { + source sourceSets.main + } + } + } + + server { + workingDirectory project.file('run') + ideaModule "${rootProject.name}.${project.name}.main" + taskName 'runServer' + property 'mixin.env.remapRefMap', 'true' + property 'mixin.env.refMapRemappingFile', "${projectDir}/build/createSrgToMcp/output.srg" + arg "-mixin.config=" + "betweenlands.mixins.json" + mods { + modServerRun { + source sourceSets.main + } + } + } + + data { + workingDirectory project.file('run') + ideaModule "${rootProject.name}.${project.name}.main" + args '--mod', mod_id, '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/') + taskName 'runData' + property 'mixin.env.remapRefMap', 'true' + property 'mixin.env.refMapRemappingFile', "${projectDir}/build/createSrgToMcp/output.srg" + mods { + modDataRun { + source sourceSets.main + } + } + } + } } -//Returns the current version by reading directly from the ModInfo.java file -project.ext.getVersionFromJava = { - String major = '0'; - String revision = '0'; - String patch = '0'; - String prefix = 'public static final String VERSION = "'; - File file = file('src/main/java/thebetweenlands/common/lib/ModInfo.java') - file.eachLine { String s -> - s = s.trim(); - if (s.startsWith(prefix)) { - s = s.substring(prefix.length(), s.length() - 2); - String[] pts = s.split('\\.'); +sourceSets.main.resources.srcDir 'src/generated/resources' - major = pts[0]; - revision = pts[1]; - patch = pts[2]; - } +repositories { + maven { + url "https://cursemaven.com" + content { includeGroup "curse.maven" } } - - return "$major.$revision.$patch"; -} - -//Returns the mod ID by reading directly from the ModInfo.java file -project.ext.getModIdFromJava = { - String id = 'N/A'; - String prefix = 'public static final String ID = "'; - File file = file('src/main/java/thebetweenlands/common/lib/ModInfo.java') - file.eachLine { String s -> - s = s.trim(); - if (s.startsWith(prefix)) { - id = s.substring(prefix.length(), s.length() - 2); - } + maven { + name = "jt-dev" + url = "https://maven.jt-dev.tech/releases" } - - return "$id"; } -//Attempts to get a project variable and if none is found it tries to read from a system environment variable -project.ext.getVariable = { key -> - return project.hasProperty(key) ? project.property(key) : ENV[key]; +dependencies { + minecraft "net.minecraftforge:forge:${rootProject.minecraft_version}-${rootProject.forge_version}" + annotationProcessor("org.spongepowered:mixin:0.8.5-SNAPSHOT:processor") } -project.ext.ENV = System.getenv() -project.ext.isDeploymentEnv = ENV['DEPLOY_ENV'] != null && 'true'.equals(ENV['DEPLOY_ENV']) -project.ext.isDeploymentRelease = project.isDeploymentEnv && ENV['DEPLOY_BUILD_TYPE'] != null && 'release'.equals(ENV['DEPLOY_BUILD_TYPE']) -project.ext.buildnumber = project.isDeploymentEnv ? ENV['DEPLOY_BUILD_NUMBER'] : '' - -project.ext.modid = project.getModIdFromJava() - -allprojects { - version = project.getVersionFromJava() - if(!isDeploymentRelease) version = version + (!project.isDeploymentRelease ? ((project.isDeploymentEnv ? ('-' + project.buildnumber) : '') + '-SNAPSHOT') : '') - - apply plugin: 'net.minecraftforge.gradle.forge' - - minecraft { - version = "1.12.2-14.23.5.2773" - runDir = 'minecraft' - replace '${version}', project.version - replace '${mcversion}', project.minecraft.version - replace '/*!ide*/true/*ide!*/', 'false' - replace '${fingerprint}', getProjectFingerprint() - clientJvmArgs = ['-Dfml.coreMods.load=thebetweenlands.core.TheBetweenlandsLoadingPlugin'] - serverJvmArgs = ['-Dfml.coreMods.load=thebetweenlands.core.TheBetweenlandsLoadingPlugin'] - - // 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 allways work. - // simply re-run your setup task after changing the mappings to update your workspace. - mappings = "stable_39" - makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable. - } - - apply from: new File(rootProject.projectDir, 'dependencies.gradle') +tasks.withType(JavaCompile).configureEach { + source(sourceSets.main.allSource) } - -//Don't build jar for root project -tasks.remove(tasks.build) - -subprojects { - //Don't set up dev env for subprojects - tasks.remove(tasks.setupCiWorkspace) - tasks.remove(tasks.setupDevWorkspace) - tasks.remove(tasks.setupDecompWorkspace) - tasks.remove(tasks.eclipse) - tasks.remove(tasks.idea) - - archivesBaseName = 'TheBetweenlands' - sourceCompatibility = targetCompatibility = '1.8' - - group = 'angrypixel' - - //Move build dir into root's build folder - buildDir = new File(rootProject.projectDir, 'build/' + project.name + '/build/') - - //Set sourceSets.main to root's sourceSets.main - sourceSets { - main { - java { - srcDir new File(rootProject.projectDir, 'src/main/java') - } - resources { - srcDir new File(rootProject.projectDir, 'src/main/resources') - } - } - } - - //Processes the resources of sourceSets.main - processResources { - inputs.property 'version', project.version - inputs.property 'mcversion', project.minecraft.version - - from (sourceSets.main.resources.srcDirs) { - include 'mcmod.info' - expand 'version':project.version, 'mcversion':project.minecraft.version - } - - from (sourceSets.main.resources.srcDirs) { exclude 'mcmod.info' } - rename '(.+_at.cfg)', 'META-INF/$1' - } - - //Set destination dir of all subprojects to build/libs/ - jar { - destinationDir = new File(rootProject.projectDir, 'build/libs/') - } - - //Adds the maven artifact attribute to the specified Manifest - project.ext.addMavenArtifactAttribute = { m, classifier -> - m.attributes ([ - 'Maven-Artifact': group + ':' + archivesBaseName + ':' + project.version + ':' + classifier, - 'Timestamp': new java.util.Date().getTime() - ]) - } +tasks.withType(Javadoc).configureEach { + source(sourceSets.main.allJava) +} +processResources { + from sourceSets.main.resources } -apply plugin: 'idea' -idea.project.modules = new ArrayList([rootProject.idea.module]) - -if(isDeploymentEnv) println('Deployment environment found') -if(isDeploymentRelease) println('Deploying a release build') - -println(canJarBeSigned() ? 'Keystore properties found, jar files will be signed' : 'No keystore properties found, jar files will not be signed') - -println('Building version ' + version) - -apply from: 'projects.gradle' \ No newline at end of file +jar.finalizedBy('reobfJar') + +publishing { + publications { + mavenJava(MavenPublication) { + artifactId base.archivesName.get() + from components.java + fg.component(it) + } + } + repositories { + maven { + url "file://" + System.getenv("local_maven") + } + } +} diff --git a/gradle.properties b/gradle.properties index 7cab1f26d2..641b39bc39 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,23 @@ -# Sets default memory used for gradle commands. Can be overridden by user or command line properties. -# This is required to provide enough memory for the Minecraft decompilation process. org.gradle.jvmargs=-Xmx4G +org.gradle.daemon=false + +## Environment Properties +# Version settings +minecraft_version=1.18.2 +minecraft_version_range=[1.18.2,1.19) + +# Mapping settings +mapping_channel=official +mapping_version=1.18.2 + +# Forge +forge_version=40.2.21 +forge_version_range=[40,) +forge_loader_version_range=[40,) + +## Mod Properties +archives_base_name=TheBetweenlands + +mod_id=thebetweenlands +mod_name=The Betweenlands +mod_version=4.0.0-dev \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index e18cba72f4..7b17ca0ba9 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.14-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip diff --git a/projects.gradle b/projects.gradle deleted file mode 100644 index c698212f57..0000000000 --- a/projects.gradle +++ /dev/null @@ -1,190 +0,0 @@ -project(':universal') { - apply from: new File(rootProject.projectDir, 'validateCoreJar.gradle') - - //Adds the universal jar manifest attributes to the specified Manifest - project.ext.addUniversalManifestAttributes = { m -> - m.attributes ([ - 'FMLAT': 'thebetweenlands_at.cfg', - 'ContainedDeps': coreJar.archivePath.name, - 'ModSide': 'BOTH' - ]) - addMavenArtifactAttribute(m, 'universal') - } - - //Adds the universal coremod manifest attributes to the specified Manifest - project.ext.addUniversalCoreManifestAttributes = { m -> - m.attributes ([ - 'FMLCorePlugin': 'thebetweenlands.core.TheBetweenlandsLoadingPlugin', - 'ModSide': 'BOTH' - ]) - addMavenArtifactAttribute(m, 'core') - } - - //Builds the universal coremod jar - task coreJar(type: Jar) { - classifier 'core' - from(sourceSets.main.output) { include 'thebetweenlands/core/**' } - project.addUniversalCoreManifestAttributes(manifest) - } - - reobf { coreJar { mappingType = 'SEARGE' } } - reobfCoreJar.dependsOn validateCoreJar //Validate core jar before reobf - - task signCoreJar(type: SignJar, dependsOn: reobfCoreJar) { - if(canJarBeSigned()) { - keyStore = getVariable('blKeyStore') - alias = getVariable('blKeyStoreAlias') - storePass = getVariable('blKeyStorePass') - keyPass = getVariable('blKeyStoreKeyPass') - inputFile = coreJar.archivePath - outputFile = coreJar.archivePath - } - } - - //Builds the universal jar - jar { - dependsOn reobfCoreJar - if(canJarBeSigned()) dependsOn signCoreJar //Sign core jar *before* including! - - classifier 'universal' - - exclude('pack.mcmeta') - exclude('pack.png') - exclude('thebetweenlands/core/**') - exclude('unused/**') - - from(coreJar.archivePath.absolutePath) { include '*' } - - project.addUniversalManifestAttributes(manifest) - } - - task signMainJar(type: SignJar, dependsOn: reobfJar) { - if(canJarBeSigned()) { - keyStore = getVariable('blKeyStore') - alias = getVariable('blKeyStoreAlias') - storePass = getVariable('blKeyStorePass') - keyPass = getVariable('blKeyStoreKeyPass') - inputFile = jar.archivePath - outputFile = jar.archivePath - } - } - - if(canJarBeSigned()) build.finalizedBy signMainJar - - //Builds the source jar with all the source files of sourceSets.main - task sourcesJar(type: Jar, dependsOn: classes) << { - classifier = 'src' - from sourceSets.main.allSource - } - - //Builds the dev jar with all the output files of sourceSets.main - task devJar(type: Jar) << { - classifier = 'dev' - from sourceSets.main.output - } - - //Builds a zip file with all client side assets - task assetsZip(type: Zip) { - dependsOn jar - classifier = 'assets' - destinationDir = new File(rootProject.projectDir, 'build/libs/') - - from (sourceSets.main.output) { - - exclude('mcmod.info') - exclude('thebetweenlands/**') - exclude("assets/${modid}/loot_tables/**") - exclude("assets/${modid}/advancements/**") - exclude("assets/${modid}/recipes/**") - exclude('META-INF/**') - exclude('unused/**') - - } - } - - artifacts { archives assetsZip/*, sourcesJar, devJar*/ } -} - -project(':server') { - apply from: new File(rootProject.projectDir, 'validateCoreJar.gradle') - - minecraft { replace '/*!server_only*/false/*server_only!*/', 'true' } - - //Adds the server jar manifest attributes to the specified Manifest - project.ext.addServerManifestAttributes = { m -> - m.attributes ([ - 'FMLAT': 'thebetweenlands_at.cfg', - 'ContainedDeps': coreJar.archivePath.name, - 'ModSide': 'SERVER' - ]) - addMavenArtifactAttribute(m, 'server') - } - - //Adds the server coremod manifest attributes to the specified Manifest - project.ext.addServerCoreManifestAttributes = { m -> - m.attributes ([ - 'FMLCorePlugin': 'thebetweenlands.core.TheBetweenlandsLoadingPlugin', - 'ModSide': 'SERVER' - ]) - addMavenArtifactAttribute(m, 'core') - } - - //Builds the server coremod jar - task coreJar(type: Jar) { - classifier 'core' - from(sourceSets.main.output) { include 'thebetweenlands/core/**' } - project.addServerCoreManifestAttributes(manifest) - } - - reobf { coreJar { mappingType = 'SEARGE' } } - reobfCoreJar.dependsOn validateCoreJar //Validate core jar before reobf - - task signCoreJar(type: SignJar, dependsOn: reobfCoreJar) { - if(canJarBeSigned()) { - keyStore = getVariable('blKeyStore') - alias = getVariable('blKeyStoreAlias') - storePass = getVariable('blKeyStorePass') - keyPass = getVariable('blKeyStoreKeyPass') - inputFile = coreJar.archivePath - outputFile = coreJar.archivePath - } - } - - //Builds the server jar - jar { - dependsOn reobfCoreJar - if(canJarBeSigned()) dependsOn signCoreJar //Sign core jar *before* including! - - classifier 'server' - - exclude('pack.mcmeta') - exclude('pack.png') - exclude('thebetweenlands/core/**') - exclude('unused/**') - - //A list of files or folders to be excluded from the server build - exclude("assets/${modid}/models/**") - exclude("assets/${modid}/shaders/**") - exclude("assets/${modid}/sounds/**") - exclude("assets/${modid}/textures/**") - exclude("assets/${modid}/sounds.json") - exclude("assets/${modid}/blockstates/**") - - from(coreJar.archivePath.absolutePath) { include '*' } - - project.addServerManifestAttributes(manifest) - } - - task signMainJar(type: SignJar, dependsOn: reobfJar) { - if(canJarBeSigned()) { - keyStore = getVariable('blKeyStore') - alias = getVariable('blKeyStoreAlias') - storePass = getVariable('blKeyStorePass') - keyPass = getVariable('blKeyStoreKeyPass') - inputFile = jar.archivePath - outputFile = jar.archivePath - } - } - - if(canJarBeSigned()) build.finalizedBy signMainJar -} \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index ca2a8a4a58..4b878c297a 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,3 +1,15 @@ +pluginManagement { + repositories { + maven { url = 'https://maven.minecraftforge.net/' } + maven { url = 'https://repo.spongepowered.org/repository/maven-public/' } + gradlePluginPortal() + } +} + +plugins { + id 'org.gradle.toolchains.foojay-resolver-convention' version '0.7.0' +} + include ':universal' project(':universal').projectDir = file('build/universal') include ':server'