Skip to content

Commit

Permalink
build: Use ModDevGradle and fabric-loom instead of archloom and Vanil…
Browse files Browse the repository at this point in the history
…laGradle (#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
  • Loading branch information
jpenilla authored Dec 4, 2024
1 parent 61898fc commit 3590b85
Show file tree
Hide file tree
Showing 19 changed files with 127 additions and 98 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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-
Expand Down
3 changes: 1 addition & 2 deletions build-logic/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ 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/")
maven("https://repo.jpenilla.xyz/snapshots/")
}

dependencies {
implementation(libs.vanillaGradle)
implementation(libs.mdg)
implementation(libs.indraCommon)
implementation(libs.indraPublishingSonatype)
implementation(libs.shadow)
Expand Down
9 changes: 2 additions & 7 deletions build-logic/src/main/kotlin/SquaremapPlatformExtension.kt
Original file line number Diff line number Diff line change
@@ -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<String>
}
abstract val modInfoFilePath: Property<String>
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
12 changes: 12 additions & 0 deletions build-logic/src/main/kotlin/squaremap.platform.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
))
}
}
}
35 changes: 2 additions & 33 deletions build-logic/src/main/kotlin/squaremap.platform.loom.gradle.kts
Original file line number Diff line number Diff line change
@@ -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<SquaremapPlatformExtension>()
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,
))
}
}
14 changes: 14 additions & 0 deletions build-logic/src/main/kotlin/squaremap.platform.mdg.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
plugins {
id("squaremap.platform.mod")
id("net.neoforged.moddev")
}

val prod = tasks.register<Zip>("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<SquaremapPlatformExtension>()
platformExt.productionJar = prod.flatMap { it.archiveFile }
24 changes: 24 additions & 0 deletions build-logic/src/main/kotlin/squaremap.platform.mod.gradle.kts
Original file line number Diff line number Diff line change
@@ -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)
}
}
8 changes: 4 additions & 4 deletions common/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions common/src/main/resources/squaremap-common-at.cfg
Original file line number Diff line number Diff line change
@@ -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;
2 changes: 1 addition & 1 deletion fabric/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion fabric/src/main/resources/squaremap-fabric.accesswidener
Original file line number Diff line number Diff line change
@@ -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;
13 changes: 7 additions & 6 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down Expand Up @@ -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]
53 changes: 39 additions & 14 deletions neoforge/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,43 +1,68 @@
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<RunGameTask>().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")
exclude("org.incendo", "cloud-processors-confirmation")
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)
Expand Down
1 change: 0 additions & 1 deletion neoforge/gradle.properties

This file was deleted.

2 changes: 1 addition & 1 deletion neoforge/src/main/resources/META-INF/accesstransformer.cfg
Original file line number Diff line number Diff line change
@@ -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;
1 change: 0 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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/")
Expand Down
Loading

0 comments on commit 3590b85

Please sign in to comment.