diff --git a/build-logic/build.gradle.kts b/build-logic/build.gradle.kts index 4076969c7f..c856fbc15b 100644 --- a/build-logic/build.gradle.kts +++ b/build-logic/build.gradle.kts @@ -12,7 +12,6 @@ repositories { dependencies { implementation(gradleApi()) - implementation(libs.grgit) implementation(libs.shadow) implementation(libs.paperweight) diff --git a/build-logic/src/main/kotlin/buildlogic.common.gradle.kts b/build-logic/src/main/kotlin/buildlogic.common.gradle.kts index c47abfe3f1..d10316edbc 100644 --- a/build-logic/src/main/kotlin/buildlogic.common.gradle.kts +++ b/build-logic/src/main/kotlin/buildlogic.common.gradle.kts @@ -5,7 +5,7 @@ import org.gradle.plugins.ide.idea.model.IdeaModel group = rootProject.group version = rootProject.version -configurations.all { +configurations.configureEach { resolutionStrategy { cacheChangingModulesFor(1, TimeUnit.DAYS) } diff --git a/build.gradle.kts b/build.gradle.kts index 2b3f0631ff..d9ac49b4a3 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,7 +1,5 @@ -import org.ajoberstar.grgit.Grgit import org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL import org.gradle.api.tasks.testing.logging.TestLogEvent.FAILED -import java.time.format.DateTimeFormatter import xyz.jpenilla.runpaper.task.RunServer plugins { @@ -18,11 +16,18 @@ var revision: String = (extra.properties["revision"] as? String) ?: "" var buildNumber: String = (extra.properties["buildNumber"] as? String) ?: "" var date: String = (extra.properties["date"] as? String) ?: "" -val git: Grgit = Grgit.open { - dir = File("$rootDir/.git") -} -date = git.head().dateTime.format(DateTimeFormatter.ofPattern("yy.MM.dd")) -revision = "-${git.head().abbreviatedId}" +// Get Git metadata during build setup using the Git CLI. +// This replaces Grgit/JGit so the build stays compatible with Gradle's configuration cache. +// The result is recorded as a build input and can be reused without re-running Git each time. +// We keep the short hash length the same as before for consistency. +fun gitOutput(vararg args: String): String = + providers.exec { + commandLine("git", *args) + workingDir = rootDir + }.standardOutput.asText.get().trim() + +date = gitOutput("show", "-s", "--format=%cd", "--date=format:%y.%m.%d", "HEAD") +revision = "-" + gitOutput("rev-parse", "--short=7", "HEAD") buildNumber = if (project.hasProperty("buildnumber")) { snapshot + "-" + (project.findProperty("buildnumber") as? String ?: "") } else { @@ -38,9 +43,8 @@ extra.set("date", date) version = String.format("%s-%s", rootVersion, snapshot) if (!project.hasProperty("gitCommitHash")) { - pluginManager.apply("org.ajoberstar.grgit") ext["gitCommitHash"] = try { - extensions.getByName("grgit").head()?.abbreviatedId + gitOutput("rev-parse", "--short=7", "HEAD") } catch (e: Exception) { logger.warn("Error getting commit hash", e) @@ -82,19 +86,17 @@ codecov { } allprojects { - gradle.projectsEvaluated { - tasks.withType().configureEach { - options.compilerArgs.addAll(arrayOf("-Xmaxerrs", "1000")) - } - tasks.withType().configureEach { - maxParallelForks = (Runtime.getRuntime().availableProcessors() / 2).takeIf { it > 0 } ?: 1 - testLogging { - events(FAILED) - exceptionFormat = FULL - showExceptions = true - showCauses = true - showStackTraces = true - } + tasks.withType().configureEach { + options.compilerArgs.addAll(arrayOf("-Xmaxerrs", "1000")) + } + tasks.withType().configureEach { + maxParallelForks = (Runtime.getRuntime().availableProcessors() / 2).takeIf { it > 0 } ?: 1 + testLogging { + events(FAILED) + exceptionFormat = FULL + showExceptions = true + showCauses = true + showStackTraces = true } } } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 2ff252a78d..294d8768f0 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -64,7 +64,6 @@ minimumJdependency = "2.10" [libraries] # Gradle plugins -grgit = { group = "org.ajoberstar.grgit", name = "grgit-gradle", version.ref = "grgit" } shadow = { group = "com.gradleup.shadow", name = "shadow-gradle-plugin", version.ref = "shadow" } paperweight = { group = "io.papermc.paperweight.userdev", name = "io.papermc.paperweight.userdev.gradle.plugin", version.ref = "paperweight" } diff --git a/worldedit-core/build.gradle.kts b/worldedit-core/build.gradle.kts index dba8ca0823..a7b190d45b 100644 --- a/worldedit-core/build.gradle.kts +++ b/worldedit-core/build.gradle.kts @@ -69,7 +69,6 @@ tasks.test { } tasks.compileJava { - dependsOn(":worldedit-libs:build") options.compilerArgs.add("-Aarg.name.key.prefix=") } @@ -103,13 +102,28 @@ sourceSets.named("main") { } } +// Resolve these to plain Strings up front. Referencing `version` or `rootProject` +// inside the filesMatching action would capture a Project instance in the task, +// which cannot be serialized by the configuration cache. +val faweVersion = "$version" +val faweCommit = "${rootProject.ext["revision"]}" +val faweDate = "${rootProject.ext["date"]}" + tasks.named("processResources") { + // Collect into a local of THIS block. A top-level `val` in a .gradle.kts is a + // property of the script object, so referencing one from the filesMatching + // closure would capture the script itself - which the configuration cache + // cannot serialize. A local is captured by value instead. + val expansions = mapOf( + "version" to faweVersion, + "commit" to faweCommit, + "date" to faweDate + ) + inputs.property("faweVersion", faweVersion) + inputs.property("faweCommit", faweCommit) + inputs.property("faweDate", faweDate) filesMatching("fawe.properties") { - expand( - "version" to "$version", - "commit" to "${rootProject.ext["revision"]}", - "date" to "${rootProject.ext["date"]}" - ) + expand(expansions) } }