-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modernize Gradle setup and allow working up to JDK 22.
- Loading branch information
1 parent
af1cd0d
commit 1a4e5b2
Showing
5 changed files
with
128 additions
and
355 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' | ||
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") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.