Skip to content

Commit 15d38b8

Browse files
authored
Merge pull request #3 from TropheusJ/fabric-26.1
Improve Gradle Practices
2 parents 4f5e41f + 49ceab6 commit 15d38b8

14 files changed

Lines changed: 172 additions & 154 deletions

.github/workflows/build.yml

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,31 @@ on:
1010
tags-ignore:
1111
- '**'
1212
pull_request:
13+
workflow_dispatch:
1314

1415
permissions:
1516
id-token: write
1617
attestations: write
1718
contents: write
1819

1920
jobs:
20-
release:
21+
build:
2122
runs-on: ubuntu-latest
2223
steps:
2324
- name: Checkout
24-
uses: actions/checkout@v4
25+
uses: actions/checkout@v6
2526

2627
- name: JDK Setup
27-
uses: actions/setup-java@v4
28+
uses: actions/setup-java@v5
2829
with:
2930
java-version: 25
3031
distribution: 'temurin'
3132

3233
- name: Gradle Setup
33-
uses: gradle/actions/setup-gradle@v4
34+
# note: setup-gradle v6+ has switched to a proprietary license.
35+
# pin this to v5 for the foreseeable future.
36+
# https://blog.gradle.org/github-actions-for-gradle-v6
37+
uses: gradle/actions/setup-gradle@v5
3438
with:
3539
validate-wrappers: true
3640

@@ -41,34 +45,31 @@ jobs:
4145
run: ./gradlew build
4246

4347
- name: Attest Build Provenance
44-
uses: actions/attest-build-provenance@v2
48+
if: github.event_name != 'pull_request'
49+
uses: actions/attest@v4
4550
with:
46-
subject-path: 'build/libs/*.jar, !build/libs/*-sources.jar'
51+
subject-path: 'build/libs/*.jar'
4752

4853
- name: Upload Artifacts
49-
uses: actions/upload-artifact@v4
54+
uses: actions/upload-artifact@v7
5055
with:
5156
name: Artifacts
52-
path: |
53-
build/libs/*.jar
54-
!build/libs/*-sources.jar
57+
path: build/libs/*.jar
5558

5659
- name: Maven Publish
5760
if: github.event_name == 'release' && github.event.action == 'published'
5861
run: ./gradlew publish
5962

6063
- name: Github Publish
6164
if: github.event_name == 'release' && github.event.action == 'published'
62-
uses: AButler/upload-release-assets@v2.0
65+
uses: AButler/upload-release-assets@v3.0
6366
with:
64-
files: 'build/libs/*.jar;!build/libs/*-sources.jar'
67+
files: 'build/libs/*.jar'
6568
repo-token: ${{ secrets.GITHUB_TOKEN }}
6669

6770
- name: Modrinth Publish
6871
env:
6972
MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }}
7073
CHANGELOG: ${{ github.event.release.body }}
7174
if: ${{ github.event_name == 'release' && github.event.action == 'published' && env.MODRINTH_TOKEN != '' }}
72-
run: |
73-
./gradlew --no-configuration-cache modrinth
74-
./gradlew --no-configuration-cache modrinthSyncBody
75+
run: ./gradlew publishMods

build.gradle

Lines changed: 0 additions & 91 deletions
This file was deleted.

build.gradle.kts

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
plugins {
2+
alias(libs.plugins.loom)
3+
alias(libs.plugins.mod.publish)
4+
`maven-publish`
5+
}
6+
7+
val modVersion: String by project
8+
val branchName: String by project
9+
val slug: String by project
10+
val compatibleVersions: String by project
11+
12+
version = "$modVersion+$branchName"
13+
14+
dependencies {
15+
minecraft(libs.minecraft)
16+
api(libs.bundles.fabric)
17+
}
18+
19+
java {
20+
withSourcesJar()
21+
toolchain.languageVersion = JavaLanguageVersion.of(25)
22+
}
23+
24+
tasks.processResources {
25+
val user: String by project
26+
val authors: String by project
27+
val contributors: String by project
28+
29+
val meta: Map<String, Any> = mapOf(
30+
"version" to project.version,
31+
"modId" to providers.gradleProperty("modId"),
32+
"modName" to providers.gradleProperty("modName"),
33+
"modDescription" to providers.gradleProperty("modDescription"),
34+
"homepage" to "https://modrinth.com/mod/$slug",
35+
"issues" to "https://github.com/$user/$slug/issues",
36+
"sources" to "https://github.com/$user/$slug",
37+
"license" to providers.gradleProperty("license"),
38+
"authors" to authors.split(", ").joinToString("\",\n \""),
39+
"contributors" to contributors.split(", ").joinToString("\",\n \""),
40+
"members" to "$authors${if (contributors.isEmpty()) "" else ". Contributions by $contributors."}",
41+
"minecraftVersion" to compatibleVersions.split(", ")[0],
42+
"fabricLoaderVersion" to libs.versions.fabric.loader,
43+
"fabricApiVersion" to libs.versions.fabric.api
44+
)
45+
46+
inputs.properties(meta)
47+
48+
filesMatching(listOf("*.mod.json", "META-INF/*mods.toml")) {
49+
// providers must be invoked manually or else you get stuff like "provider(?)" instead of "mod-id"
50+
expand(meta.mapValues { when (val value = it.value) {
51+
is Provider<*> -> value.get()
52+
else -> value
53+
}})
54+
}
55+
}
56+
57+
publishing {
58+
publications {
59+
register<MavenPublication>("mavenJava") {
60+
from(components["java"])
61+
}
62+
}
63+
}
64+
65+
publishMods {
66+
file = tasks.jar.flatMap { it.archiveFile }
67+
additionalFiles.from(tasks.named("sourcesJar"))
68+
changelog = providers.environmentVariable("CHANGELOG")
69+
70+
type = version.map { when {
71+
it.contains("alpha") -> ALPHA
72+
it.contains("beta") -> BETA
73+
else -> STABLE
74+
}}
75+
76+
val compatibleLoaders: String by project
77+
val readme: RegularFile = rootProject.layout.projectDirectory.file("README.md")
78+
79+
modrinth {
80+
projectId = slug
81+
accessToken = providers.environmentVariable("MODRINTH_TOKEN")
82+
83+
minecraftVersions.addAll(compatibleVersions.split(", "))
84+
modLoaders.addAll(compatibleLoaders.split(", "))
85+
86+
projectDescription = providers.fileContents(readme).asText.map {
87+
"<!--DO NOT EDIT MANUALLY: synced from gh readme-->\n$it"
88+
}
89+
90+
requires {
91+
slug = "fabric-api"
92+
version = libs.versions.fabric.api
93+
}
94+
}
95+
}

gradle.properties

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1-
# Gradle
2-
org.gradle.jvmargs=-Xmx2G -XX:MaxMetaspaceSize=512m -Dfile.encoding=UTF-8
1+
# Allocate additional memory to the Gradle JVM. The default is often not enough to decompile Minecraft.
2+
org.gradle.jvmargs=-Xmx2G
3+
4+
# Various flags to optimize Gradle performance.
5+
org.gradle.parallel=true
36
org.gradle.caching=true
4-
org.gradle.configureondemand=true
57
org.gradle.configuration-cache=true
6-
# Loom
7-
fabric.loom.multiProjectOptimisation=true
8+
org.gradle.configuration-cache.parallel=true
9+
org.gradle.configureondemand=true
10+
11+
# Enable all Gradle warnings
12+
org.gradle.warning.mode=all
13+
814
# Mod Metadata
915
group=io.github.username
1016
user=username

gradle/libs.versions.toml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[versions]
2+
loom = "1.15.+"
3+
mod-publish = "1.1.0"
4+
5+
minecraft = "26.1.1"
6+
# https://fabricmc.net/develop/
7+
fabric-loader = "0.18.4"
8+
fabric-api = "0.145.4+26.1.1"
9+
10+
[plugins]
11+
loom = { id = "net.fabricmc.fabric-loom", version.ref = "loom" }
12+
mod-publish = { id = "me.modmuss50.mod-publish-plugin", version.ref = "mod-publish" }
13+
14+
[libraries]
15+
minecraft = { group = "mojang", name = "minecraft", version.ref = "minecraft" }
16+
fabric-loader = { group = "net.fabricmc", name = "fabric-loader", version.ref = "fabric-loader" }
17+
fabric-api = { group = "net.fabricmc.fabric-api", name = "fabric-api", version.ref = "fabric-api" }
18+
19+
[bundles]
20+
fabric = [ "fabric-loader", "fabric-api" ]

gradle/wrapper/gradle-wrapper.jar

5.08 KB
Binary file not shown.

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-9.3.1-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-9.4.1-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

gradlew

Lines changed: 2 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gradlew.bat

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libs.versions.toml

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)