From e6b509f90379907347cb5b483b720b3d55c900bf Mon Sep 17 00:00:00 2001 From: Raven Szewczyk Date: Thu, 29 Jun 2023 18:06:05 +0100 Subject: [PATCH 01/10] Make maven publishing and the target URL configurable --- build.gradle | 18 +++++++++++------- gradle.properties | 6 ++++++ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/build.gradle b/build.gradle index 39309904..1c82375b 100644 --- a/build.gradle +++ b/build.gradle @@ -69,7 +69,7 @@ plugins { id 'com.diffplug.spotless' version '6.13.0' apply false // 6.13.0 is the last jvm8 supporting version id 'com.modrinth.minotaur' version '2.+' apply false id 'com.matthewprenger.cursegradle' version '1.4.0' apply false - id 'com.gtnewhorizons.retrofuturagradle' version '1.3.14' + id 'com.gtnewhorizons.retrofuturagradle' version '1.3.19' } print("You might want to check out './gradlew :faq' if your build fails.\n") @@ -115,6 +115,8 @@ propertyDefaultIfUnset("usesMixinDebug", project.usesMixins) propertyDefaultIfUnset("forceEnableMixins", false) propertyDefaultIfUnset("channel", "stable") propertyDefaultIfUnset("mappingsVersion", "12") +propertyDefaultIfUnset("usesMavenPublishing", true) +propertyDefaultIfUnset("mavenPublishUrl", "http://jenkins.usrv.eu:8081/nexus/content/repositories/releases") propertyDefaultIfUnset("modrinthProjectId", "") propertyDefaultIfUnset("modrinthRelations", "") propertyDefaultIfUnset("curseForgeProjectId", "") @@ -1118,12 +1120,14 @@ publishing { } repositories { - maven { - url = "http://jenkins.usrv.eu:8081/nexus/content/repositories/releases" - allowInsecureProtocol = true - credentials { - username = System.getenv("MAVEN_USER") ?: "NONE" - password = System.getenv("MAVEN_PASSWORD") ?: "NONE" + if (usesMavenPublishing.toBoolean()) { + maven { + url = mavenPublishUrl + allowInsecureProtocol = true // Mostly for the GTNH maven + credentials { + username = System.getenv("MAVEN_USER") ?: "NONE" + password = System.getenv("MAVEN_PASSWORD") ?: "NONE" + } } } } diff --git a/gradle.properties b/gradle.properties index 94513255..9f30763d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -91,6 +91,12 @@ relocateShadowedDependencies = true # Adds the GTNH maven, CurseMaven, IC2/Player maven, and some more well-known 1.7.10 repositories includeWellKnownRepositories = true +# Change these to your Maven coordinates if you want to publish to a custom Maven repository instead of the default GTNH Maven. +# Authenticate with the MAVEN_USERNAME and MAVEN_PASSWORD environment variables. +# If you need a more complex setup disable maven publishing here and add a publishing repository to addon.gradle. +usesMavenPublishing = true +# mavenPublishUrl = http://jenkins.usrv.eu:8081/nexus/content/repositories/releases + # Publishing to modrinth requires you to set the MODRINTH_TOKEN environment variable to your current modrinth API token. # The project's ID on Modrinth. Can be either the slug or the ID. From 00fc82f284cb4181ae273aeb86bef7576d6b1433 Mon Sep 17 00:00:00 2001 From: Raven Szewczyk Date: Thu, 29 Jun 2023 18:08:31 +0100 Subject: [PATCH 02/10] Add a Build&Test gradle task for convenience --- build.gradle | 3 +++ 1 file changed, 3 insertions(+) diff --git a/build.gradle b/build.gradle index 1c82375b..9e8d8407 100644 --- a/build.gradle +++ b/build.gradle @@ -981,6 +981,9 @@ idea { } } runConfigurations { + "0. Build and Test"(Gradle) { + taskNames = ["build"] + } "1. Run Client"(Gradle) { taskNames = ["runClient"] } From 1b8e7a8ff22b1ad5e2082b4c132bcf2bff61c5e1 Mon Sep 17 00:00:00 2001 From: Raven Szewczyk Date: Thu, 29 Jun 2023 18:19:46 +0100 Subject: [PATCH 03/10] Make IJ project build more useful by building jars and running spotless --- build.gradle | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/build.gradle b/build.gradle index 9e8d8407..a6822d22 100644 --- a/build.gradle +++ b/build.gradle @@ -1103,6 +1103,11 @@ tasks.named("processIdeaSettings").configure { dependsOn("injectTags") } +tasks.named("ideVirtualMainClasses").configure { + // Make IntelliJ "Build project" build the mod jars + dependsOn("jar", "reobfJar", "spotlessCheck") +} + // workaround variable hiding in pom processing def projectConfigs = project.configurations From 209c382ecdee0b901720ac40eb03f5fb91b40167 Mon Sep 17 00:00:00 2001 From: Raven Szewczyk Date: Thu, 29 Jun 2023 18:32:39 +0100 Subject: [PATCH 04/10] Allow kotlin scripts, add addon.late.gradle for eval-order-dependent addon scripts --- .gitignore | 4 ++++ README.md | 12 ++++++------ build.gradle | 43 ++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 50 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 39c072d3..5f5fc937 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,7 @@ src/main/resources/mixins.*([!.]).json *.DS_Store !gradlew.bat .factorypath +addon.local.gradle +addon.local.gradle.kts +addon.late.local.gradle +addon.late.local.gradle.kts diff --git a/README.md b/README.md index 33687247..b389db42 100644 --- a/README.md +++ b/README.md @@ -46,8 +46,8 @@ We also have described guidelines for existing mod [migration](docs/migration.md ### Files - [`build.gradle`](https://github.com/GTNewHorizons/ExampleMod1.7.10/blob/main/build.gradle): This is the core script of the build process. You should not need to tamper with it, unless you are trying to accomplish something out of the ordinary. __Do not touch this file! You will make a future update near impossible if you do so!__ - [`gradle.properties`](https://github.com/GTNewHorizons/ExampleMod1.7.10/blob/main/gradle.properties): The core configuration file. It includes - - [`dependencies.gradle`](https://github.com/GTNewHorizons/ExampleMod1.7.10/blob/main/dependencies.gradle): Add your mod's dependencies in this file. This is separate from the main build script, so you may replace the [`build.gradle`](https://github.com/SinTh0r4s/ExampleMod1.7.10/blob/main/build.gradle) if an update is available. - - [`repositories.gradle`](https://github.com/GTNewHorizons/ExampleMod1.7.10/blob/main/repositories.gradle): Add your dependencies' repositories. This is separate from the main build script, so you may replace the [`build.gradle`](https://github.com/SinTh0r4s/ExampleMod1.7.10/blob/main/build.gradle) if an update is available. + - [`dependencies.gradle[.kts]`](https://github.com/GTNewHorizons/ExampleMod1.7.10/blob/main/dependencies.gradle): Add your mod's dependencies in this file. This is separate from the main build script, so you may replace the [`build.gradle`](https://github.com/SinTh0r4s/ExampleMod1.7.10/blob/main/build.gradle) if an update is available. + - [`repositories.gradle[.kts]`](https://github.com/GTNewHorizons/ExampleMod1.7.10/blob/main/repositories.gradle): Add your dependencies' repositories. This is separate from the main build script, so you may replace the [`build.gradle`](https://github.com/SinTh0r4s/ExampleMod1.7.10/blob/main/build.gradle) if an update is available. - [`jitpack.yml`](https://github.com/GTNewHorizons/ExampleMod1.7.10/blob/main/jitpack.yml): Ensures that your mod is available as import over [Jitpack](https://jitpack.io). - [`.github/workflows/gradle.yml`](https://github.com/GTNewHorizons/ExampleMod1.7.10/blob/main/.github/workflows/gradle.yml): A simple CI script that will build your mod any time it is pushed to `master` or `main` and publish the result as release in your repository. This feature is free with GitHub if your repository is public. @@ -64,13 +64,13 @@ __Warning:__ Access Transformers are bugged and will deny you any sources for th Mixins are usually used to modify vanilla or mod/library in runtime without having to change source code. For example, redirect a call, change visibility or make class implement your interface. It's an advanced topic and most mods don't need to do that. You can activate Mixin in 'gradle.properties'. In that case a mixin configuration (usually named `mixins.mymodid.json`) will be generated automatically, and you only have to write the mixins itself. Dependencies are handled as well. -Take a look at the examples in [`com.myname.mymodid.mixinplugin.*`](https://github.com/GTNewHorizons/ExampleMod1.7.10/tree/example-mixins/src/main/java/com/myname/mymodid/mixinplugin) and [`com.myname.mymodid.mixins.*`](https://github.com/GTNewHorizons/ExampleMod1.7.10/tree/example-mixins/src/main/java/com/myname/mymodid/mixins). - -Check out the [`example-mixins`](https://github.com/GTNewHorizons/ExampleMod1.7.10/tree/example-mixins) brach for a working example! +Take a look at the examples in [Hodgepodge](https://github.com/GTNewHorizons/Hodgepodge/) and [Angelica](https://github.com/GTNewHorizons/Angelica/pull/8). ### Advanced -If your project requires custom gradle commands you may add a `addon.gradle` to your project. It will be added automatically to the build script. Although we recommend against it, it is sometimes required. When in doubt, feel free to ask us about it. You may break future updates of this build system! +If your project requires custom gradle commands you may add a `addon.gradle[.kts]` to your project. It will be added automatically to the build script. Although we recommend against it, it is sometimes required. When in doubt, feel free to ask us about it. You may break future updates of this build system! +If you need access to properties modified later in the buildscript, you can also use a `addon.late.gradle[.kts]`. +For local tweaks that you don't want to commit to Git, like adding extra JVM arguments for testing, use `addon[.late].local.gradle[.kts]`. ### Feedback wanted diff --git a/build.gradle b/build.gradle index a6822d22..401210da 100644 --- a/build.gradle +++ b/build.gradle @@ -467,10 +467,19 @@ sourceSets { } } -if (file('addon.gradle').exists()) { +if (file('addon.gradle.kts').exists()) { + apply from: 'addon.gradle.kts' +} else if (file('addon.gradle').exists()) { apply from: 'addon.gradle' } +// File for local tweaks not commited to Git +if (file('addon.local.gradle.kts').exists()) { + apply from: 'addon.local.gradle.kts' +} else if (file('addon.local.gradle').exists()) { + apply from: 'addon.local.gradle' +} + // Allow unsafe repos but warn repositories.configureEach { repo -> if (repo instanceof org.gradle.api.artifacts.repositories.UrlArtifactRepository) { @@ -481,7 +490,14 @@ repositories.configureEach { repo -> } } -apply from: 'repositories.gradle' +if (file('repositories.gradle.kts').exists()) { + apply from: 'repositories.gradle.kts' +} else if (file('repositories.gradle').exists()) { + apply from: 'repositories.gradle' +} else { + logger.error("Neither repositories.gradle.kts nor repositories.gradle was found, make sure you extracted the full ExampleMod template.") + throw new RuntimeException("Missing repositories.gradle[.kts]") +} configurations { runtimeClasspath.extendsFrom(runtimeOnlyNonPublishable) @@ -613,7 +629,14 @@ configurations.all { } } -apply from: 'dependencies.gradle' +if (file('dependencies.gradle.kts').exists()) { + apply from: 'dependencies.gradle.kts' +} else if (file('dependencies.gradle').exists()) { + apply from: 'dependencies.gradle' +} else { + logger.error("Neither dependencies.gradle.kts nor dependencies.gradle was found, make sure you extracted the full ExampleMod template.") + throw new RuntimeException("Missing dependencies.gradle[.kts]") +} def mixingConfigRefMap = 'mixins.' + modId + '.refmap.json' def mixinTmpDir = buildDir.path + File.separator + 'tmp' + File.separator + 'mixins' @@ -1522,3 +1545,17 @@ def getSecondaryArtifacts() { if (apiPackage) secondaryArtifacts += [apiJar] return secondaryArtifacts } + +// For easier scripting of things that require variables defined earlier in the buildscript +if (file('addon.late.gradle.kts').exists()) { + apply from: 'addon.late.gradle.kts' +} else if (file('addon.late.gradle').exists()) { + apply from: 'addon.late.gradle' +} + +// File for local tweaks not commited to Git +if (file('addon.late.local.gradle.kts').exists()) { + apply from: 'addon.late.local.gradle.kts' +} else if (file('addon.late.local.gradle').exists()) { + apply from: 'addon.late.local.gradle' +} From cae3750060cdacda23fc0a2ceddefe46b3ab8a2a Mon Sep 17 00:00:00 2001 From: Raven Szewczyk Date: Thu, 29 Jun 2023 18:41:29 +0100 Subject: [PATCH 05/10] Bump lwjgl3ify&hodgepodge --- build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 401210da..a7fbcb7d 100644 --- a/build.gradle +++ b/build.gradle @@ -749,13 +749,13 @@ ext.java17PatchDependenciesCfg = configurations.create("java17PatchDependencies" } dependencies { - def lwjgl3ifyVersion = '1.3.5' + def lwjgl3ifyVersion = '1.4.0' def asmVersion = '9.4' if (modId != 'lwjgl3ify') { java17Dependencies("com.github.GTNewHorizons:lwjgl3ify:${lwjgl3ifyVersion}") } if (modId != 'hodgepodge') { - java17Dependencies('com.github.GTNewHorizons:Hodgepodge:2.2.13') + java17Dependencies('com.github.GTNewHorizons:Hodgepodge:2.2.19') } java17PatchDependencies('net.minecraft:launchwrapper:1.15') {transitive = false} From 0034728370a490e459a1655c8b46532e244068c7 Mon Sep 17 00:00:00 2001 From: Raven Szewczyk Date: Thu, 29 Jun 2023 18:52:42 +0100 Subject: [PATCH 06/10] Fix duplicate mod errors when old gtnhlib is present in the dependency tree --- build.gradle | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/build.gradle b/build.gradle index a7fbcb7d..03a8011d 100644 --- a/build.gradle +++ b/build.gradle @@ -629,6 +629,24 @@ configurations.all { } } +dependencies { + constraints { + def minGtnhLibVersion = "0.0.13" + implementation("com.github.GTNewHorizons:GTNHLib:${minGtnhLibVersion}") { + because("fixes duplicate mod errors in java 17 configurations using old gtnhlib") + } + runtimeOnly("com.github.GTNewHorizons:GTNHLib:${minGtnhLibVersion}") { + because("fixes duplicate mod errors in java 17 configurations using old gtnhlib") + } + devOnlyNonPublishable("com.github.GTNewHorizons:GTNHLib:${minGtnhLibVersion}") { + because("fixes duplicate mod errors in java 17 configurations using old gtnhlib") + } + runtimeOnlyNonPublishable("com.github.GTNewHorizons:GTNHLib:${minGtnhLibVersion}") { + because("fixes duplicate mod errors in java 17 configurations using old gtnhlib") + } + } +} + if (file('dependencies.gradle.kts').exists()) { apply from: 'dependencies.gradle.kts' } else if (file('dependencies.gradle').exists()) { From 0fa6311c8cfde735fbeed3f8ebc0b56c993d385f Mon Sep 17 00:00:00 2001 From: Raven Szewczyk Date: Thu, 29 Jun 2023 18:59:16 +0100 Subject: [PATCH 07/10] Only allowInsecureProtocol when starts with http --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 03a8011d..6db5e740 100644 --- a/build.gradle +++ b/build.gradle @@ -1172,7 +1172,7 @@ publishing { if (usesMavenPublishing.toBoolean()) { maven { url = mavenPublishUrl - allowInsecureProtocol = true // Mostly for the GTNH maven + allowInsecureProtocol = mavenPublishUrl.startsWith("http://") // Mostly for the GTNH maven credentials { username = System.getenv("MAVEN_USER") ?: "NONE" password = System.getenv("MAVEN_PASSWORD") ?: "NONE" From c20beedf4113d124a4bc76b4eb523f4a6f60080c Mon Sep 17 00:00:00 2001 From: Raven Szewczyk Date: Thu, 29 Jun 2023 19:03:21 +0100 Subject: [PATCH 08/10] Don't crash when update check fails --- build.gradle | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 6db5e740..52a3cd77 100644 --- a/build.gradle +++ b/build.gradle @@ -1397,7 +1397,12 @@ boolean isNewBuildScriptVersionAvailable() { String currentBuildScript = getFile("build.gradle").getText() String currentBuildScriptHash = getVersionHash(currentBuildScript) - String availableBuildScript = availableBuildScriptUrl().newInputStream(parameters).getText() + try { + String availableBuildScript = availableBuildScriptUrl().newInputStream(parameters).getText() + } catch (IOException e) { + logger.warn("Could not check for buildscript update availability: {}", e.message) + return false + } String availableBuildScriptHash = getVersionHash(availableBuildScript) boolean isUpToDate = currentBuildScriptHash.empty || availableBuildScriptHash.empty || currentBuildScriptHash == availableBuildScriptHash From deb7ac805216e15d18a8a892f6441d5b7fbcce71 Mon Sep 17 00:00:00 2001 From: Raven Szewczyk Date: Thu, 29 Jun 2023 19:39:54 +0100 Subject: [PATCH 09/10] Fix derp --- build.gradle | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 52a3cd77..e8cd02b4 100644 --- a/build.gradle +++ b/build.gradle @@ -1397,13 +1397,14 @@ boolean isNewBuildScriptVersionAvailable() { String currentBuildScript = getFile("build.gradle").getText() String currentBuildScriptHash = getVersionHash(currentBuildScript) + String availableBuildScriptHash try { String availableBuildScript = availableBuildScriptUrl().newInputStream(parameters).getText() + availableBuildScriptHash = getVersionHash(availableBuildScript) } catch (IOException e) { logger.warn("Could not check for buildscript update availability: {}", e.message) return false } - String availableBuildScriptHash = getVersionHash(availableBuildScript) boolean isUpToDate = currentBuildScriptHash.empty || availableBuildScriptHash.empty || currentBuildScriptHash == availableBuildScriptHash return !isUpToDate From 6d86834ff86a8dacdc4e8a1a83b7706c7fccd4cd Mon Sep 17 00:00:00 2001 From: Raven Szewczyk Date: Thu, 29 Jun 2023 20:36:44 +0100 Subject: [PATCH 10/10] Make dirty version numbers follow semver conventions more --- build.gradle | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index e8cd02b4..47a49de9 100644 --- a/build.gradle +++ b/build.gradle @@ -359,7 +359,24 @@ catch (Exception ignored) { String identifiedVersion String versionOverride = System.getenv("VERSION") ?: null try { - identifiedVersion = versionOverride == null ? gitVersion() : versionOverride + // Produce a version based on the tag, or for branches something like 0.2.2-configurable-maven-and-extras.38+43090270b6-dirty + if (versionOverride == null) { + def gitDetails = versionDetails() + def isDirty = gitVersion().endsWith(".dirty") // No public API for this, isCleanTag has a different meaning + String branchName = gitDetails.branchName + branchName = branchName.replaceAll("[^a-zA-Z0-9-]+", "-") // sanitize branch names for semver + identifiedVersion = gitDetails.lastTag + if (gitDetails.commitDistance > 0) { + identifiedVersion += "-${branchName}.${gitDetails.commitDistance}+${gitDetails.gitHash}" + if (isDirty) { + identifiedVersion += "-dirty" + } + } else if (isDirty) { + identifiedVersion += "-${branchName}+${gitDetails.gitHash}-dirty" + } + } else { + identifiedVersion = versionOverride + } } catch (Exception ignored) { out.style(Style.Failure).text(