Skip to content

Commit 651c669

Browse files
committed
Integrate crankcase-git for Git metadata handling.
1 parent 5ac8f9c commit 651c669

4 files changed

Lines changed: 18 additions & 9 deletions

File tree

build-logic/build.gradle.kts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,17 @@ repositories {
88
name = "EngineHub Repository"
99
url = uri("https://maven.enginehub.org/repo/")
1010
}
11+
maven {
12+
name = "EngineHub Releases"
13+
url = uri("https://repo.enginehub.org/libs-release/")
14+
}
1115
}
1216

1317
dependencies {
1418
implementation(gradleApi())
1519
implementation(libs.shadow)
1620
implementation(libs.paperweight)
21+
implementation(libs.crankcase.git)
1722

1823
constraints {
1924
val asmVersion = "[${libs.versions.minimumAsm.get()},)"

build-logic/src/main/kotlin/buildlogic.common.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ import buildlogic.getLibrary
22
import buildlogic.stringyLibs
33
import org.gradle.plugins.ide.idea.model.IdeaModel
44

5+
plugins {
6+
id("org.enginehub.crankcase.git")
7+
}
8+
59
group = rootProject.group
610
version = rootProject.version
711

build.gradle.kts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ var date: String = (extra.properties["date"] as? String) ?: ""
1919
// Get Git metadata during build setup using the Git CLI.
2020
// This replaces Grgit/JGit so the build stays compatible with Gradle's configuration cache.
2121
// The result is recorded as a build input and can be reused without re-running Git each time.
22-
// We keep the short hash length the same as before for consistency.
22+
// crankcase-git has no commit-date accessor, so `date` still goes through this directly.
2323
fun gitOutput(vararg args: String): String =
2424
providers.exec {
2525
commandLine("git", *args)
2626
workingDir = rootDir
2727
}.standardOutput.asText.get().trim()
2828

2929
date = gitOutput("show", "-s", "--format=%cd", "--date=format:%y.%m.%d", "HEAD")
30-
revision = "-" + gitOutput("rev-parse", "--short=7", "HEAD")
30+
revision = "-" + git.commitHash.get()
3131
buildNumber = if (project.hasProperty("buildnumber")) {
3232
snapshot + "-" + (project.findProperty("buildnumber") as? String ?: "")
3333
} else {
@@ -42,14 +42,12 @@ extra.set("date", date)
4242

4343
version = String.format("%s-%s", rootVersion, snapshot)
4444

45-
if (!project.hasProperty("gitCommitHash")) {
46-
ext["gitCommitHash"] = try {
47-
gitOutput("rev-parse", "--short=7", "HEAD")
48-
} catch (e: Exception) {
49-
logger.warn("Error getting commit hash", e)
45+
ext["gitCommitHash"] = try {
46+
git.commitHash.get()
47+
} catch (e: Exception) {
48+
logger.warn("Error getting commit hash", e)
5049

51-
"no.git.id"
52-
}
50+
"no.git.id"
5351
}
5452

5553
val totalReport = tasks.register<JacocoReport>("jacocoTotalReport") {

gradle/libs.versions.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ shadow = "9.5.1"
5757
paperweight = "2.0.0-SNAPSHOT"
5858
codecov = "0.3.0"
5959
jqwik = "1.10.1"
60+
crankcase = "0.1.2"
6061

6162
# Minimum versions we apply to make dependencies support newer Java
6263
minimumAsm = "9.7"
@@ -66,6 +67,7 @@ minimumJdependency = "2.10"
6667
# Gradle plugins
6768
shadow = { group = "com.gradleup.shadow", name = "shadow-gradle-plugin", version.ref = "shadow" }
6869
paperweight = { group = "io.papermc.paperweight.userdev", name = "io.papermc.paperweight.userdev.gradle.plugin", version.ref = "paperweight" }
70+
crankcase-git = { group = "org.enginehub.crankcase", name = "git", version.ref = "crankcase" }
6971

7072
# Minecraft expectations
7173
paperApi = { group = "io.papermc.paper", name = "paper-api", version.ref = "paperApi" }

0 commit comments

Comments
 (0)