Skip to content

Commit c2ada7c

Browse files
phraktleclaude
andcommitted
build: make build.gradle Gradle 9 configuration-cache compatible
Paired with the Gradle 9.4.1 wrapper bump: make the root and imgui-binding build scripts usable under Gradle 9's configuration cache (the default for downstream consumers on Gradle 9+). Three changes: - build.gradle: replace Groovy 'git describe'.execute() with providers.exec (cache-aware external process API). Same for 'git rev-parse HEAD' in the jar manifest block. - imgui-binding/build.gradle: capture project.version.toString() into a local at configuration time, and pass that through the processResources filesMatching closure rather than letting the closure resolve `version` against the live Project model at execution time. Without this, any downstream consumer running Gradle 9 with configuration cache on (including `includeBuild` composite builds) hits: - Starting an external process 'git describe --tags --always' during configuration time is unsupported. - Invocation of 'version' references a Gradle script object from a Groovy closure at execution time, which is unsupported with the configuration cache. Verified: `./gradlew :imgui-binding:compileJava --configuration-cache` now stores a configuration cache entry cleanly on Gradle 9.4.1. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent afa8835 commit c2ada7c

2 files changed

Lines changed: 20 additions & 3 deletions

File tree

build.gradle

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,21 @@ ext {
66
lwjglVersion = '3.4.1'
77
}
88

9+
// Gradle 9's configuration cache forbids starting external processes at
10+
// configuration time via Groovy's '...'.execute() (the cache can't know
11+
// if the result would be different next time). Use providers.exec, which
12+
// is cache-aware.
13+
def gitDescribeProvider = providers.exec {
14+
commandLine 'git', 'describe', '--tags', '--always'
15+
}.standardOutput.asText.map { it.trim().startsWith('v') ? it.trim().substring(1) : it.trim() }.orElse('unknown')
16+
17+
def gitRevProvider = providers.exec {
18+
commandLine 'git', 'rev-parse', 'HEAD'
19+
}.standardOutput.asText.map { it.trim() }.orElse('unknown')
20+
921
allprojects {
1022
group = 'imgui-java'
11-
version = 'git describe --tags --always'.execute().text.trim().substring(1)
23+
version = gitDescribeProvider.get()
1224

1325
repositories {
1426
mavenCentral()
@@ -23,13 +35,14 @@ allprojects {
2335

2436
def jdkMetadata = tasks.withType(JavaCompile).find().javaCompiler.get().metadata
2537
def buildJdk = "${jdkMetadata.javaRuntimeVersion} (${jdkMetadata.vendor})".toString()
38+
def buildRev = gitRevProvider.get()
2639

2740
manifest {
2841
attributes (
2942
'Implementation-Title': project.name,
3043
'Implementation-Version': project.version,
3144
'Build-Timestamp': new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ").format(System.currentTimeMillis()),
32-
'Build-Revision': 'git rev-parse HEAD'.execute().text.trim(),
45+
'Build-Revision': buildRev,
3346
'Build-Jdk': buildJdk,
3447
'Source-Compatibility': tasks.withType(JavaCompile).find().sourceCompatibility,
3548
'Target-Compatibility': tasks.withType(JavaCompile).find().targetCompatibility,

imgui-binding/build.gradle

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,14 @@ jar {
5151
}
5252
}
5353

54+
// Capture project.version at configuration time so the closure below does not
55+
// reference the Project model at execution time -- Gradle 9 configuration cache
56+
// requirement.
57+
def processVersion = project.version.toString()
5458
processResources {
5559
filesMatching('**/imgui-java.properties') {
5660
filter(ReplaceTokens, tokens: [
57-
'version': version
61+
'version': processVersion
5862
])
5963
}
6064
}

0 commit comments

Comments
 (0)