Skip to content

Commit b4cd279

Browse files
jamesarichclaude
andcommitted
chore(build): harden the version resolution the previous commit moved
Two review findings on the moved block, both pre-existing behavior the move preserved verbatim; fixing them here keeps the move itself pure. git describe now passes --exclude "v*-*" so a prerelease-shaped tag (v0.9.0-rc1) is never read as a release: describe falls back to the last stable tag and the existing arithmetic yields the usual next-patch SNAPSHOT. No such tags exist in this repo today, so this changes nothing retroactively. resolvedVersion is validated as MAJOR.MINOR.PATCH[-suffix] at settings evaluation. sample/androidApp destructures exactly three toInt() components out of project.version, so a blank or two-part version previously surfaced as a bare NumberFormatException deep in that module; now configuration fails immediately and names the offending value. Verified both ways: -PVERSION_NAME=bogus fails with the new message, and the full gate (spotlessCheck detektAll allTests apiCheck koverVerify) passes on the git-derived version. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent 65e2a82 commit b4cd279

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

settings.gradle.kts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ dependencyResolutionManagement {
3535
// equivalent and needs no cross-project access.
3636
// ---------------------------------------------------------------------------
3737
val gitVersion: Provider<String> = providers.exec {
38-
commandLine("git", "describe", "--tags", "--match", "v*")
38+
// --exclude keeps prerelease-shaped tags (v0.9.0-rc1) from being read as releases: describe then
39+
// falls back to the last stable tag and the arithmetic below yields the usual next-patch SNAPSHOT.
40+
commandLine("git", "describe", "--tags", "--match", "v*", "--exclude", "v*-*")
3941
isIgnoreExitValue = true
4042
}.standardOutput.asText.map { raw ->
4143
val desc = raw.trim()
@@ -57,6 +59,14 @@ val resolvedVersion: String =
5759
providers.gradleProperty("VERSION_NAME")
5860
.orElse(gitVersion)
5961
.get()
62+
.also { version ->
63+
// Fail configuration with a message that names the problem: sample/androidApp derives its
64+
// versionCode by destructuring MAJOR.MINOR.PATCH with toInt(), so a blank or two-part
65+
// version would otherwise surface as a bare NumberFormatException deep in that module.
66+
require(version.matches(Regex("\\d+\\.\\d+\\.\\d+(-.+)?"))) {
67+
"Version '$version' is not MAJOR.MINOR.PATCH[-suffix]; check the VERSION_NAME property or git tags"
68+
}
69+
}
6070

6171
// Copied into a local before the lambda closes over it: a top-level `val` in a settings script is a
6272
// field of the script object, so referencing it directly would capture the script itself — which the

0 commit comments

Comments
 (0)