From 3590b8527df65a5a08ce8827a60e892222147a21 Mon Sep 17 00:00:00 2001 From: Jason Penilla <11360596+jpenilla@users.noreply.github.com> Date: Wed, 4 Dec 2024 16:56:38 -0700 Subject: [PATCH] build: Use ModDevGradle and fabric-loom instead of archloom and VanillaGradle (#341) * build: Use ModDevGradle and fabric-loom instead of archloom and VanillaGradle * remove redundant configuration this is done by indra * Cache build/moddev * Don't cache VanillaGradle * cache fabric loom cache --- .github/workflows/build.yml | 5 +- build-logic/build.gradle.kts | 3 +- .../main/kotlin/SquaremapPlatformExtension.kt | 9 +--- .../squaremap.base-conventions.gradle.kts | 5 -- .../main/kotlin/squaremap.platform.gradle.kts | 12 +++++ .../kotlin/squaremap.platform.loom.gradle.kts | 35 +----------- .../kotlin/squaremap.platform.mdg.gradle.kts | 14 +++++ .../kotlin/squaremap.platform.mod.gradle.kts | 24 +++++++++ common/build.gradle.kts | 8 +-- .../main/resources/squaremap-common-at.cfg | 3 ++ fabric/build.gradle.kts | 2 +- .../resources/squaremap-fabric.accesswidener | 2 +- gradle/libs.versions.toml | 13 ++--- neoforge/build.gradle.kts | 53 ++++++++++++++----- neoforge/gradle.properties | 1 - .../resources/META-INF/accesstransformer.cfg | 2 +- settings.gradle.kts | 1 - sponge/build.gradle.kts | 30 ++++------- .../resources/squaremap-sponge.accesswidener | 3 +- 19 files changed, 127 insertions(+), 98 deletions(-) create mode 100644 build-logic/src/main/kotlin/squaremap.platform.mdg.gradle.kts create mode 100644 build-logic/src/main/kotlin/squaremap.platform.mod.gradle.kts create mode 100644 common/src/main/resources/squaremap-common-at.cfg delete mode 100644 neoforge/gradle.properties rename common/src/main/resources/squaremap-common.accesswidener => sponge/src/main/resources/squaremap-sponge.accesswidener (54%) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index eea02cdc..49538c3b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -26,9 +26,12 @@ jobs: uses: actions/cache@v4 with: path: | - .gradle/caches/VanillaGradle .gradle/loom-cache + fabric/.gradle/loom-cache paper/.gradle/caches/paperweight + common/build/moddev + neoforge/build/moddev + sponge/build/moddev key: ${{ runner.os }}-project-local-gradle-caches-${{ hashFiles('**/libs.versions.toml', '**/*.gradle*', '**/gradle-wrapper.properties') }} restore-keys: | ${{ runner.os }}-project-local-gradle-caches- diff --git a/build-logic/build.gradle.kts b/build-logic/build.gradle.kts index fe6bceec..c24daf2b 100644 --- a/build-logic/build.gradle.kts +++ b/build-logic/build.gradle.kts @@ -6,7 +6,6 @@ repositories { gradlePluginPortal() mavenCentral() maven("https://repo.papermc.io/repository/maven-public/") - maven("https://repo.spongepowered.org/repository/maven-public/") maven("https://maven.fabricmc.net/") maven("https://maven.neoforged.net/releases/") maven("https://maven.architectury.dev/") @@ -14,7 +13,7 @@ repositories { } dependencies { - implementation(libs.vanillaGradle) + implementation(libs.mdg) implementation(libs.indraCommon) implementation(libs.indraPublishingSonatype) implementation(libs.shadow) diff --git a/build-logic/src/main/kotlin/SquaremapPlatformExtension.kt b/build-logic/src/main/kotlin/SquaremapPlatformExtension.kt index 879a623a..74968ff8 100644 --- a/build-logic/src/main/kotlin/SquaremapPlatformExtension.kt +++ b/build-logic/src/main/kotlin/SquaremapPlatformExtension.kt @@ -1,14 +1,9 @@ import org.gradle.api.file.RegularFileProperty -import org.gradle.api.model.ObjectFactory import org.gradle.api.provider.Property -import org.gradle.kotlin.dsl.newInstance import javax.inject.Inject -abstract class SquaremapPlatformExtension @Inject constructor(objects: ObjectFactory) { +abstract class SquaremapPlatformExtension @Inject constructor() { abstract val productionJar: RegularFileProperty - val loom: Loom = objects.newInstance(Loom::class) - abstract class Loom { - abstract val modInfoFilePath: Property - } + abstract val modInfoFilePath: Property } diff --git a/build-logic/src/main/kotlin/squaremap.base-conventions.gradle.kts b/build-logic/src/main/kotlin/squaremap.base-conventions.gradle.kts index c9ae00b3..cc079efd 100644 --- a/build-logic/src/main/kotlin/squaremap.base-conventions.gradle.kts +++ b/build-logic/src/main/kotlin/squaremap.base-conventions.gradle.kts @@ -39,8 +39,3 @@ tasks.withType(JavaCompile::class).configureEach { // missing annotation (values), or Java serialization options.compilerArgs.add("-Xlint:-processing,-classfile,-serial") } - -tasks.withType(AbstractArchiveTask::class).configureEach { - isReproducibleFileOrder = true - isPreserveFileTimestamps = false -} diff --git a/build-logic/src/main/kotlin/squaremap.platform.gradle.kts b/build-logic/src/main/kotlin/squaremap.platform.gradle.kts index e1144107..4f765464 100644 --- a/build-logic/src/main/kotlin/squaremap.platform.gradle.kts +++ b/build-logic/src/main/kotlin/squaremap.platform.gradle.kts @@ -56,3 +56,15 @@ publishMods.modrinth { changelog = releaseNotes accessToken = providers.environmentVariable("MODRINTH_TOKEN") } + +afterEvaluate { + if (platformExt.modInfoFilePath.isPresent) { + tasks.processResources { + expandIn(platformExt.modInfoFilePath.get(), mapOf( + "version" to project.version, + "github_url" to rootProject.providers.gradleProperty("githubUrl").get(), + "description" to project.description, + )) + } + } +} diff --git a/build-logic/src/main/kotlin/squaremap.platform.loom.gradle.kts b/build-logic/src/main/kotlin/squaremap.platform.loom.gradle.kts index 588bbacd..aee1dde4 100644 --- a/build-logic/src/main/kotlin/squaremap.platform.loom.gradle.kts +++ b/build-logic/src/main/kotlin/squaremap.platform.loom.gradle.kts @@ -1,38 +1,7 @@ plugins { - id("squaremap.platform") - id("xyz.jpenilla.quiet-architectury-loom") + id("squaremap.platform.mod") + id("quiet-fabric-loom") } val platformExt = extensions.getByType() platformExt.productionJar = tasks.remapJar.flatMap { it.archiveFile } - -val shade: Configuration by configurations.creating -configurations.implementation { - extendsFrom(shade) -} -val shadeFiltered: Configuration by configurations.creating { - extendsFrom(shade) - - exclude("org.checkerframework") -} - -tasks { - shadowJar { - configurations = listOf(shadeFiltered) - listOf( - "jakarta.inject", - "com.google.inject", - "org.aopalliance", - ).forEach(::reloc) - } -} - -afterEvaluate { - tasks.processResources { - expandIn(platformExt.loom.modInfoFilePath.get(), mapOf( - "version" to project.version, - "github_url" to rootProject.providers.gradleProperty("githubUrl").get(), - "description" to project.description, - )) - } -} diff --git a/build-logic/src/main/kotlin/squaremap.platform.mdg.gradle.kts b/build-logic/src/main/kotlin/squaremap.platform.mdg.gradle.kts new file mode 100644 index 00000000..993432ec --- /dev/null +++ b/build-logic/src/main/kotlin/squaremap.platform.mdg.gradle.kts @@ -0,0 +1,14 @@ +plugins { + id("squaremap.platform.mod") + id("net.neoforged.moddev") +} + +val prod = tasks.register("productionJar") { + destinationDirectory = layout.buildDirectory.dir("libs") + from(zipTree(tasks.shadowJar.flatMap { it.archiveFile })) + // for some reason the inner jars were getting unpacked when from'ing directly to shadowJar...? + from(tasks.jarJar) +} + +val platformExt = extensions.getByType() +platformExt.productionJar = prod.flatMap { it.archiveFile } diff --git a/build-logic/src/main/kotlin/squaremap.platform.mod.gradle.kts b/build-logic/src/main/kotlin/squaremap.platform.mod.gradle.kts new file mode 100644 index 00000000..fc1c5ec4 --- /dev/null +++ b/build-logic/src/main/kotlin/squaremap.platform.mod.gradle.kts @@ -0,0 +1,24 @@ +plugins { + id("squaremap.platform") +} + +val shade: Configuration by configurations.creating +configurations.implementation { + extendsFrom(shade) +} +val shadeFiltered: Configuration by configurations.creating { + extendsFrom(shade) + + exclude("org.checkerframework") +} + +tasks { + shadowJar { + configurations = listOf(shadeFiltered) + listOf( + "jakarta.inject", + "com.google.inject", + "org.aopalliance", + ).forEach(::reloc) + } +} diff --git a/common/build.gradle.kts b/common/build.gradle.kts index 1998a333..fe16eeb9 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -1,11 +1,11 @@ plugins { id("squaremap.base-conventions") - id("org.spongepowered.gradle.vanilla") + id("net.neoforged.moddev") } -minecraft { - version().set(libs.versions.minecraft) - accessWideners(layout.projectDirectory.file("src/main/resources/squaremap-common.accesswidener")) +neoForge { + neoFormVersion = libs.versions.neoform + accessTransformers.from(layout.projectDirectory.file("src/main/resources/squaremap-common-at.cfg")) } dependencies { diff --git a/common/src/main/resources/squaremap-common-at.cfg b/common/src/main/resources/squaremap-common-at.cfg new file mode 100644 index 00000000..f30a7c95 --- /dev/null +++ b/common/src/main/resources/squaremap-common-at.cfg @@ -0,0 +1,3 @@ +# Any ATs declared here must be applied on all platforms (in one way or another) + +public net.minecraft.world.level.chunk.PalettedContainer get(I)Ljava/lang/Object; diff --git a/fabric/build.gradle.kts b/fabric/build.gradle.kts index 1f57ada1..4e317f01 100644 --- a/fabric/build.gradle.kts +++ b/fabric/build.gradle.kts @@ -48,7 +48,7 @@ dependencies { include(libs.cardinalComponentsEntity) } -squaremapPlatform.loom.modInfoFilePath = "fabric.mod.json" +squaremapPlatform.modInfoFilePath = "fabric.mod.json" tasks.remapJar { archiveFileName = productionJarName(libs.versions.minecraft) diff --git a/fabric/src/main/resources/squaremap-fabric.accesswidener b/fabric/src/main/resources/squaremap-fabric.accesswidener index cd2152c2..6e58bce9 100644 --- a/fabric/src/main/resources/squaremap-fabric.accesswidener +++ b/fabric/src/main/resources/squaremap-fabric.accesswidener @@ -1,4 +1,4 @@ accessWidener v1 named -# below are manually copied from squaremap-common.accesswidener, be sure to keep up to date with changes +# below are manually copied from squaremap-common-at.cfg, be sure to keep up to date with changes accessible method net/minecraft/world/level/chunk/PalettedContainer get (I)Ljava/lang/Object; diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 4ee4fde2..6c9e8c41 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -25,16 +25,17 @@ fabricLoader = "0.16.9" cardinalComponents = "6.2.0" guice = "7.0.0" neoforge = "21.3.42-beta" +neoform = "1.21.3-20241023.131943" htmlSanitizer = "20240325.1" # buildSrc indra = "3.1.3" sponge-gradle = "2.2.0" shadow = "8.3.5" -vanillaGradle = "0.2.1-SNAPSHOT" mod-publish-plugin = "0.8.1" -loom = "1.7-SNAPSHOT" -paperweight = "1.7.5" +loom = "1.8-SNAPSHOT" +mdg = "2.0.52-beta" +paperweight = "1.7.6" [libraries] guice = { group = "com.google.inject", name = "guice", version.ref = "guice" } @@ -93,15 +94,15 @@ minecraft = { group = "com.mojang", name = "minecraft", version.ref = "minecraft cardinalComponentsBase = { group = "org.ladysnake.cardinal-components-api", name = "cardinal-components-base", version.ref = "cardinalComponents" } cardinalComponentsEntity = { group = "org.ladysnake.cardinal-components-api", name = "cardinal-components-entity", version.ref = "cardinalComponents" } -neoforge = { group = "net.neoforged", name = "neoforge", version.ref = "neoforge" } +zNeoforge = { group = "net.neoforged", name = "neoforge", version.ref = "neoforge" } # buildSrc indraCommon = { group = "net.kyori", name = "indra-common", version.ref = "indra" } indraPublishingSonatype = { group = "net.kyori", name = "indra-publishing-sonatype", version.ref = "indra" } shadow = { group = "com.gradleup.shadow", name = "shadow-gradle-plugin", version.ref = "shadow" } -vanillaGradle = { group = "org.spongepowered", name = "vanillagradle", version.ref = "vanillaGradle" } mod-publish-plugin = { module = "me.modmuss50:mod-publish-plugin", version.ref = "mod-publish-plugin" } -loom = { group = "xyz.jpenilla", name = "quiet-architectury-loom", version.ref = "loom" } +loom = { module = "net.fabricmc:quiet-fabric-loom", version.ref = "loom" } +mdg = { module = "net.neoforged:moddev-gradle", version.ref = "mdg" } paperweightUserdev = { group = "io.papermc.paperweight", name = "paperweight-userdev", version.ref = "paperweight" } [bundles] diff --git a/neoforge/build.gradle.kts b/neoforge/build.gradle.kts index 831e1c04..6e58d546 100644 --- a/neoforge/build.gradle.kts +++ b/neoforge/build.gradle.kts @@ -1,16 +1,41 @@ +import net.neoforged.moddevgradle.internal.RunGameTask + plugins { - id("squaremap.platform.loom") + id("squaremap.platform.mdg") } repositories { maven("https://maven.neoforged.net/releases/") } -dependencies { - minecraft(libs.minecraft) - mappings(loom.officialMojangMappings()) - neoForge(libs.neoforge) +neoForge { + version = libs.versions.neoforge + runs { + register("client") { + client() + } + register("server") { + server() + } + configureEach { + loadedMods.set(emptySet()) + } + } +} +tasks.withType().configureEach { + dependsOn(tasks.productionJar) + doFirst { + val mods = gameDirectory.get().asFile.resolve("mods") + mods.mkdirs() + tasks.productionJar.get().archiveFile.get().asFile.copyTo( + mods.resolve("squaremap.jar"), + overwrite = true + ) + } +} + +dependencies { shade(projects.squaremapCommon) { exclude("org.incendo", "cloud-core") exclude("org.incendo", "cloud-minecraft-extras") @@ -18,26 +43,26 @@ dependencies { exclude("io.leangen.geantyref") } - modImplementation(libs.adventurePlatformNeoforge) - include(libs.adventurePlatformNeoforge) + implementation(libs.adventurePlatformNeoforge) + jarJar(libs.adventurePlatformNeoforge) - modImplementation(libs.cloudNeoForge) - include(libs.cloudNeoForge) + implementation(libs.cloudNeoForge) + jarJar(libs.cloudNeoForge) implementation(libs.cloudMinecraftExtras) { isTransitive = false // we depend on adventure separately } - include(libs.cloudMinecraftExtras) + jarJar(libs.cloudMinecraftExtras) implementation(libs.cloudConfirmation) - include(libs.cloudConfirmation) - include(libs.cloudProcessorsCommon) + jarJar(libs.cloudConfirmation) + jarJar(libs.cloudProcessorsCommon) } -tasks.remapJar { +tasks.productionJar { archiveFileName = productionJarName(libs.versions.minecraft) } -squaremapPlatform.loom.modInfoFilePath = "META-INF/neoforge.mods.toml" +squaremapPlatform.modInfoFilePath = "META-INF/neoforge.mods.toml" publishMods.modrinth { minecraftVersions.add(libs.versions.minecraft) diff --git a/neoforge/gradle.properties b/neoforge/gradle.properties deleted file mode 100644 index 7da18ea6..00000000 --- a/neoforge/gradle.properties +++ /dev/null @@ -1 +0,0 @@ -loom.platform=neoforge diff --git a/neoforge/src/main/resources/META-INF/accesstransformer.cfg b/neoforge/src/main/resources/META-INF/accesstransformer.cfg index 71681858..8fbc4a77 100644 --- a/neoforge/src/main/resources/META-INF/accesstransformer.cfg +++ b/neoforge/src/main/resources/META-INF/accesstransformer.cfg @@ -1,2 +1,2 @@ -# below are manually copied from squaremap-common.accesswidener, be sure to keep up to date with changes +# below are manually copied from squaremap-common-at.cfg, be sure to keep up to date with changes public net.minecraft.world.level.chunk.PalettedContainer get(I)Ljava/lang/Object; diff --git a/settings.gradle.kts b/settings.gradle.kts index 23c8f2e1..85300d52 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -4,7 +4,6 @@ pluginManagement { repositories { gradlePluginPortal() mavenCentral() - maven("https://repo.spongepowered.org/repository/maven-public/") maven("https://maven.fabricmc.net/") maven("https://maven.neoforged.net/releases/") maven("https://maven.architectury.dev/") diff --git a/sponge/build.gradle.kts b/sponge/build.gradle.kts index c05f462e..8b3cd0a2 100644 --- a/sponge/build.gradle.kts +++ b/sponge/build.gradle.kts @@ -2,24 +2,22 @@ import org.spongepowered.gradle.plugin.config.PluginLoaders import org.spongepowered.plugin.metadata.model.PluginDependency plugins { - id("squaremap.platform") + id("squaremap.platform.mdg") alias(libs.plugins.sponge.gradle.plugin) - id("org.spongepowered.gradle.vanilla") alias(libs.plugins.sponge.gradle.ore) } val minecraftVersion = libs.versions.minecraft -minecraft { - version().set(minecraftVersion) - accessWideners(project(":squaremap-common").layout.projectDirectory.file("src/main/resources/squaremap-common.accesswidener")) +neoForge { + neoFormVersion = libs.versions.neoform } dependencies { - implementation(projects.squaremapCommon) { + shade(projects.squaremapCommon) { exclude("io.leangen.geantyref") } - implementation(libs.cloudSponge) { + shade(libs.cloudSponge) { exclude("io.leangen.geantyref") } compileOnly("javax.inject:javax.inject:1") @@ -28,20 +26,18 @@ dependencies { } // https://github.com/SpongePowered/SpongeGradle/issues/70 -/* configurations.spongeRuntime { resolutionStrategy { eachDependency { if (target.name == "spongevanilla") { - useVersion("1.20.+") + useVersion("1.21.3-13.+") } } } } - */ sponge { - apiVersion("12.0.0-SNAPSHOT") + apiVersion("13.0.0-SNAPSHOT") plugin("squaremap") { loader { name(PluginLoaders.JAVA_PLAIN) @@ -57,26 +53,22 @@ sponge { } tasks { - shadowJar { + productionJar { archiveFileName.set(productionJarName(minecraftVersion)) + } + shadowJar { listOf( "org.incendo.cloud", - "com.google.inject", - "jakarta.inject", ).forEach(::reloc) manifest { attributes( - "Access-Widener" to "squaremap-common.accesswidener", + "Access-Widener" to "squaremap-sponge.accesswidener", "MixinConfigs" to "squaremap-sponge.mixins.json", ) } } } -squaremapPlatform { - productionJar.set(tasks.shadowJar.flatMap { it.archiveFile }) -} - oreDeployment { defaultPublication { versionBody.set(releaseNotes) diff --git a/common/src/main/resources/squaremap-common.accesswidener b/sponge/src/main/resources/squaremap-sponge.accesswidener similarity index 54% rename from common/src/main/resources/squaremap-common.accesswidener rename to sponge/src/main/resources/squaremap-sponge.accesswidener index 5558dc5f..6e58bce9 100644 --- a/common/src/main/resources/squaremap-common.accesswidener +++ b/sponge/src/main/resources/squaremap-sponge.accesswidener @@ -1,5 +1,4 @@ accessWidener v1 named -# Any AWs declared here must be applied on all platforms (in one way or another) - +# below are manually copied from squaremap-common-at.cfg, be sure to keep up to date with changes accessible method net/minecraft/world/level/chunk/PalettedContainer get (I)Ljava/lang/Object;