Fix runGit to use ProcessBuilder for AGP 9 compatibility

This commit is contained in:
2026-02-24 12:11:21 +01:00
parent 756a3da783
commit 01a342582c

View File

@@ -1,5 +1,3 @@
import java.io.ByteArrayOutputStream
plugins { plugins {
alias(libs.plugins.android.application) alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.compose) alias(libs.plugins.kotlin.compose)
@@ -9,6 +7,14 @@ plugins {
} }
// ── Git-based versioning ──────────────────────────────────── // ── Git-based versioning ────────────────────────────────────
fun runGit(vararg args: String): String = try {
val proc = ProcessBuilder("git", *args)
.directory(rootProject.projectDir)
.redirectErrorStream(true)
.start()
proc.inputStream.bufferedReader().readText().trim().also { proc.waitFor() }
} catch (_: Exception) { "" }
// Version name from latest git tag (e.g. v0.1.0 -> "0.1.0") // Version name from latest git tag (e.g. v0.1.0 -> "0.1.0")
fun gitVersionName(): String = runGit("describe", "--tags", "--abbrev=0") fun gitVersionName(): String = runGit("describe", "--tags", "--abbrev=0")
.removePrefix("v") .removePrefix("v")
@@ -23,23 +29,8 @@ fun buildNumber(): Int {
fun gitShortHash(): String = runGit("rev-parse", "--short", "HEAD") fun gitShortHash(): String = runGit("rev-parse", "--short", "HEAD")
.ifEmpty { "unknown" } .ifEmpty { "unknown" }
// Display: "0.1.0+6.abc1234" // Display: "0.1.0+7.abc1234"
fun gitDisplayVersion(): String { fun gitDisplayVersion(): String = "${gitVersionName()}+${buildNumber()}.${gitShortHash()}"
val base = gitVersionName()
val build = buildNumber()
val hash = gitShortHash()
return "$base+$build.$hash"
}
fun runGit(vararg args: String): String = try {
val out = ByteArrayOutputStream()
project.exec {
commandLine("git", *args)
standardOutput = out
isIgnoreExitValue = true
}
out.toString().trim()
} catch (_: Exception) { "" }
// ───────────────────────────────────────────────────────────── // ─────────────────────────────────────────────────────────────