Update to Gradle 9, Loom 1.15, EGT 0.7

This commit is contained in:
Jonas Herzig
2026-03-28 09:18:04 +01:00
parent f08607a599
commit b72fad4055
11 changed files with 52 additions and 42 deletions

View File

@@ -1,31 +1,42 @@
import groovy.json.JsonOutput
import java.io.ByteArrayOutputStream
import org.gradle.kotlin.dsl.support.serviceOf
import org.gradle.process.ExecOperations
plugins {
id("gg.essential.multi-version.root")
id("gg.essential.loom") version "1.7.35" apply false
id("gg.essential.loom") version "1.15.48" apply false
id("com.github.hierynomus.license") version "0.15.0"
}
val latestVersion = file("version.txt").readLines().first()
var releaseCommit = command("git", "blame", "-p", "-l", "version.txt").first().split(" ").first()
var releaseCommit = providers.exec {
commandLine("git", "blame", "-p", "-l", "version.txt")
}.standardOutput.asText.map { it.trim().split("/n").first().split(" ").first() }.get()
if (latestVersion == "2.1.0") { // First version since change from tag-based
releaseCommit = "35ac26e91689ac9bdf12dbb9902c452464a75108" // git rev-parse 1.12.2-2.1.0
}
val currentCommit = command("git", "rev-parse", "HEAD").first()
val currentCommit = providers.exec {
commandLine("git", "rev-parse", "HEAD")
}.standardOutput.asText.map { it.trim().split("/n").first() }.get()
if (releaseCommit == currentCommit) {
version = latestVersion
} else {
val diff = command("git", "log", "--format=oneline", "$releaseCommit..$currentCommit").size
val diff = providers.exec {
commandLine("git", "log", "--format=oneline", "$releaseCommit..$currentCommit")
}.standardOutput.asText.map { it.trim().split("/n").size }.get()
version = "$latestVersion-$diff-g${currentCommit.substring(0, 7)}"
}
if (gitDescribe().endsWith("*")) {
val dirty = providers.exec {
commandLine("git", "describe", "--always", "--dirty=*")
}.standardOutput.asText.map { it.trim().endsWith("*") }.get()
if (dirty) {
version = "$version-dirty"
}
group = "com.replaymod"
val bundleJar by tasks.creating(Copy::class) {
val bundleJar by tasks.registering(Copy::class) {
into("$buildDir/libs")
}
@@ -45,26 +56,15 @@ subprojects {
afterEvaluate {
val projectBundleJar = project.tasks.findByName("bundleJar")
if (projectBundleJar != null && projectBundleJar.hasProperty("archivePath") && project.name != "core") {
bundleJar.dependsOn(projectBundleJar)
bundleJar.from(projectBundleJar.withGroovyBuilder { getProperty("archivePath") })
bundleJar.configure {
dependsOn(projectBundleJar)
from(projectBundleJar.withGroovyBuilder { getProperty("archivePath") })
}
}
}
}
fun gitDescribe(): String {
try {
val stdout = ByteArrayOutputStream()
exec {
commandLine("git", "describe", "--always", "--dirty=*")
standardOutput = stdout
}
return stdout.toString().trim()
} catch (e: Throwable) {
return "unknown"
}
}
fun command(vararg cmd: Any): List<String> {
fun ExecOperations.command(vararg cmd: String): List<String> {
val stdout = ByteArrayOutputStream()
exec {
commandLine(*cmd)
@@ -73,7 +73,10 @@ fun command(vararg cmd: Any): List<String> {
return stdout.toString().trim().split("\n")
}
fun generateVersionsJson(): Map<String, Any> {
fun generateVersionsJson(execOps: ExecOperations): Map<String, Any> {
fun command(vararg cmd: String): List<String> =
execOps.command(*cmd)
val versionComparator = compareBy<String>(
{ (it.split(".").getOrNull(0) ?: "0").toInt() },
{ (it.split(".").getOrNull(1) ?: "0").toInt() },
@@ -145,18 +148,24 @@ fun generateVersionsJson(): Map<String, Any> {
}
val writeVersionsJson by tasks.registering {
val execOps = project.serviceOf<ExecOperations>()
doLast {
val versionsRoot = generateVersionsJson()
val versionsRoot = generateVersionsJson(execOps)
val versionsJson = JsonOutput.prettyPrint(JsonOutput.toJson(versionsRoot))
File("versions.json").writeText(versionsJson)
}
}
val doRelease by tasks.registering {
val execOps = project.serviceOf<ExecOperations>()
doLast {
fun command(vararg cmd: String): List<String> =
execOps.command(*cmd)
// Parse version
val version = project.extra["releaseVersion"] as String
if (gitDescribe().endsWith("*")) {
if (command("git", "describe", "--always", "--dirty=*").first().endsWith("*")) {
throw InvalidUserDataException("Git working tree is dirty. Make sure to commit all changes.")
}
val (modVersion, preVersion) = if ("-b" in version) {
@@ -181,7 +190,7 @@ val doRelease by tasks.registering {
command("git", "commit", "-m", commitMessage)
// Generate versions.json content
val versionsRoot = generateVersionsJson()
val versionsRoot = generateVersionsJson(execOps)
val versionsJson = JsonOutput.prettyPrint(JsonOutput.toJson(versionsRoot))
// Switch to master branch to update versions.json
@@ -191,11 +200,11 @@ val doRelease by tasks.registering {
File("versions.json").writeText(versionsJson)
// Commit changes
project.exec { commandLine("git", "add", "versions.json") }
project.exec { commandLine("git", "commit", "-m", "Update versions.json for $version") }
command("git", "add", "versions.json")
command("git", "commit", "-m", "Update versions.json for $version")
// Return to previous branch
project.exec { commandLine("git", "checkout", "-") }
command("git", "checkout", "-")
}
}