Skip to content

Commit

Permalink
Rework the Gradle build scripts for multi-loader
Browse files Browse the repository at this point in the history
* Shared logic is moved into a build plugin where possible
* Build time is significantly improved when the Gradle daemon is warmed
* Mixins are remapped in-place now, eliminating the need for refmaps
  at runtime. This also gets rid of some warning messages at startup.
* Module relationships are now correctly represented in IDEA for other
  source sets (fixes a lot of code analysis features)
* Split Java source and resources into different configurations
* Run configurations are now consistent between NeoForge/Fabric
* The common project is no longer remapped unnecessarily
* Updated Gradle and build plugins
  • Loading branch information
jellysquid3 committed Oct 26, 2024
1 parent 65068c5 commit dc7dc4c
Show file tree
Hide file tree
Showing 20 changed files with 337 additions and 336 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: sodium-artifacts-${{ steps.ref.outputs.branch }}
path: build/libs/*.jar
path: build/mods/*.jar
2 changes: 1 addition & 1 deletion .github/workflows/build-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: sodium-artifacts-${{ steps.ref.outputs.branch }}
path: build/libs/*.jar
path: build/mods/*.jar
3 changes: 1 addition & 2 deletions .github/workflows/build-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,5 @@ jobs:
- name: Upload assets to GitHub
uses: AButler/[email protected]
with:
# Filter built files to disregard -sources and -dev, and leave only the minecraft-compatible jars.
files: 'build/libs/*[0-9].jar;LICENSE'
files: 'build/mods/*.jar'
repo-token: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/build-tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: sodium-artifacts-${{ steps.ref.outputs.branch }}
path: build/libs/*.jar
path: build/mods/*.jar
84 changes: 0 additions & 84 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,84 +0,0 @@
plugins {
id("java")
id("fabric-loom") version ("1.7.3") apply (false)
}

val MINECRAFT_VERSION by extra { "1.21.1" }
val NEOFORGE_VERSION by extra { "21.1.46" }
val FABRIC_LOADER_VERSION by extra { "0.16.4" }
val FABRIC_API_VERSION by extra { "0.103.0+1.21.1" }

// This value can be set to null to disable Parchment.
// TODO: Re-add Parchment
val PARCHMENT_VERSION by extra { null }

// https://semver.org/
val MOD_VERSION by extra { "0.6.0-beta.2" }

allprojects {
apply(plugin = "java")
apply(plugin = "maven-publish")
}

tasks.withType<JavaCompile> {
options.encoding = "UTF-8"
}

// Disable the default publish task if it exists
tasks.replace("publish").dependsOn(":fabric:publish", ":neoforge:publish")
tasks.replace("publishToMavenLocal").dependsOn(":fabric:publishToMavenLocal", ":neoforge:publishToMavenLocal")

tasks.jar {
enabled = false
}

subprojects {
apply(plugin = "maven-publish")

java.toolchain.languageVersion = JavaLanguageVersion.of(21)


fun createVersionString(): String {
val builder = StringBuilder()

val isReleaseBuild = project.hasProperty("build.release")
val buildId = System.getenv("GITHUB_RUN_NUMBER")

if (isReleaseBuild) {
builder.append(MOD_VERSION)
} else {
builder.append(MOD_VERSION.substringBefore('-'))
builder.append("-snapshot")
}

builder.append("+mc").append(MINECRAFT_VERSION)

if (!isReleaseBuild) {
if (buildId != null) {
builder.append("-build.${buildId}")
} else {
builder.append("-local")
}
}

return builder.toString()
}

tasks.processResources {
filesMatching("META-INF/neoforge.mods.toml") {
expand(mapOf("version" to createVersionString()))
}
}

version = createVersionString()
group = "net.caffeinemc.mods"

tasks.withType<JavaCompile> {
options.encoding = "UTF-8"
options.release.set(21)
}

tasks.withType<GenerateModuleMetadata>().configureEach {
enabled = false
}
}
8 changes: 8 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
plugins {
`kotlin-dsl`
}

repositories {
mavenCentral()
gradlePluginPortal()
}
13 changes: 13 additions & 0 deletions buildSrc/src/main/kotlin/BuildConfig.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
object BuildConfig {
val MINECRAFT_VERSION: String = "1.21.1"
val NEOFORGE_VERSION: String = "21.1.46"
val FABRIC_LOADER_VERSION: String = "0.16.4"
val FABRIC_API_VERSION: String = "0.103.0+1.21.1"

// This value can be set to null to disable Parchment.
// TODO: Re-add Parchment
val PARCHMENT_VERSION: String? = null

// https://semver.org/
val MOD_VERSION: String = "0.6.0-beta.2"
}
44 changes: 44 additions & 0 deletions buildSrc/src/main/kotlin/multiloader-base.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
plugins {
id("java-library")
id("idea")
}

group = "net.caffeinemc"
version = BuildConfig.MOD_VERSION

java.toolchain.languageVersion = JavaLanguageVersion.of(21)

tasks.withType<JavaCompile> {
options.encoding = "UTF-8"
options.release.set(21)
}

tasks.withType<GenerateModuleMetadata>().configureEach {
enabled = false
}

repositories {
exclusiveContent {
forRepository {
maven {
name = "Modrinth"
url = uri("https://api.modrinth.com/maven")
}
}
filter {
includeGroup("maven.modrinth")
}
}

exclusiveContent {
forRepository {
maven {
name = "Parchment"
url = uri("https://maven.parchmentmc.org")
}
}
filter {
includeGroup("org.parchmentmc.data")
}
}
}
43 changes: 43 additions & 0 deletions buildSrc/src/main/kotlin/multiloader-platform.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
plugins {
id("multiloader-base")
id("maven-publish")
}

val configurationDesktopIntegrationJava: Configuration = configurations.create("commonDesktopIntegration") {
isCanBeResolved = true
}

dependencies {
configurationDesktopIntegrationJava(project(path = ":common", configuration = "commonDesktopJava"))
}

tasks {
processResources {
inputs.property("version", BuildConfig.MOD_VERSION)

filesMatching(listOf("fabric.mod.json", "META-INF/neoforge.mods.toml")) {
expand(mapOf("version" to BuildConfig.MOD_VERSION))
}
}

jar {
duplicatesStrategy = DuplicatesStrategy.FAIL
from(rootDir.resolve("LICENSE.md"))

// Entry-point for desktop integration when the file is executed directly
from(configurationDesktopIntegrationJava)
manifest.attributes["Main-Class"] = "net.caffeinemc.mods.sodium.desktop.LaunchWarn"
}
}

publishing {
publications {
create<MavenPublication>("maven") {
groupId = project.group as String
artifactId = project.name as String
version = BuildConfig.MOD_VERSION

from(components["java"])
}
}
}
Loading

0 comments on commit dc7dc4c

Please sign in to comment.