Repository navigation
Fix overlapping task outputs preventing build cache usage - #15532
Conversation
GrailsGradlePlugin.configureGroovyCompiler() adds the same output file
(build/grailsGroovyCompilerConfig.groovy) to every GroovyCompile task
in a project. When a project has multiple GroovyCompile tasks (e.g.
compileGroovy, compileTestGroovy, compileIntegrationTestGroovy), Gradle
detects overlapping outputs and refuses to cache any of them.
Fix: use a task-specific config file name
(grailsGroovyCompilerConfig-{taskName}.groovy) so each GroovyCompile
task has a unique output path.
Similarly, GrailsCodeStylePlugin redirects Checkstyle and CodeNarc
reports to rootProject.buildDir/reports/codestyle/{tool}/{project}.xml.
Projects with multiple source sets (e.g. grails-cache has ast + main)
have multiple tasks writing to the same report file. Fix: include the
task name in the report file path.
The :grails-test-examples-micronaut:integrationTest task contains Ersatz mock server tests that fail non-deterministically (different tests fail on each run). This causes experiment 1 and 3 to fail with exit code 2 when the first build hits the flaky test. Overlapping task outputs causing 325 cache misses in experiment 2 are addressed in upstream PR: apache/grails-core#15532
This comment has been minimized.
This comment has been minimized.
The configureForkSettings() method sets BuildSettings.APP_BASE_DIR to project.projectDir.absolutePath as a system property on all Test and JavaExec tasks. Since system properties are @input on Test tasks, this absolute path becomes part of the cache key, preventing cache hits when the project is built from a different directory. Replace the direct systemProperty call with a CommandLineArgumentProvider that declares the project directory as @InputDirectory with @PathSensitive(RELATIVE). This way the directory content is still tracked for correctness, but the absolute path no longer affects the cache key. Note: GroovyCompile, Checkstyle, CodeNarc, and Groovydoc tasks still have relocatability issues due to SourceTask.getSource() defaulting to @PathSensitive(ABSOLUTE) in Gradle itself. This is a Gradle-level limitation that cannot be addressed in grails-core.
The CycloneDX SBOM rewrite uses buildDate (which defaults to Instant.now() without SOURCE_DATE_EPOCH) for the metadata timestamp. This non-reproducible timestamp also changes the serialNumber UUID (derived from JSON content). The SBOM is embedded in META-INF/sbom.json inside every jar, so changed jars cascade cache misses through the compile classpath of downstream projects. Fix: use a fixed epoch (Instant.EPOCH) as the SBOM timestamp when SOURCE_DATE_EPOCH is not set. The serialNumber UUID then also becomes deterministic. Release builds with SOURCE_DATE_EPOCH continue to use the real build date.
|
Added two more commits on top of the overlapping outputs fix: Normalize Make SBOM timestamp reproducible — The CycloneDX SBOM rewrite uses Remaining: |
This comment has been minimized.
This comment has been minimized.
GrailsAppBaseDirProvider annotated the project directory with @InputDirectory, making every Test and JavaExec task declare the entire project directory as a file input. Since build/ lives inside the project directory, Gradle detects implicit dependency violations between the consuming task (e.g. test) and every task that writes into build/ (compileIntegrationTestGroovy, jar, groovydoc, javadocJar, etc.). Change the annotation to @internal — this property only passes a system property value to the forked JVM and should not be tracked as a file system input. The actual inputs (classpath, source sets) are already properly tracked by their respective tasks.
✅ All tests passed ✅🏷️ Commit: a5b18b2 Learn more about TestLens at testlens.app. |
| * by their respective tasks. | ||
| */ | ||
| @CompileStatic | ||
| class GrailsAppBaseDirProvider implements CommandLineArgumentProvider { |
There was a problem hiding this comment.
I'd just like to say: this is genius. I've been trying to figure out a way to fix this and I very much appreciate this solution.
|
This question isn’t related to the pull request. I can only help with questions about the PR’s code or comments. |
jdaugherty
left a comment
There was a problem hiding this comment.
@matrei Can you please check this out one more time? If you agree, I'll merge.
|
@ribafish I opened gradle/gradle#38395 - apparently sometime between the latest gradle release and gradle 8, this stopped working as i would expect. =( |
…ssons Encode durable Gradle lessons from merged 8.0.x/7.x PRs so agents write acceptable monorepo build changes on the first try. - Build cacheability rules from #15483, #15532, #15537 (portable test props, no overlapping outputs, SBOM classpath normalization, upToDateWhen traps) - base.dir dual rule: required @internal compile provider, forbidden absolute Test.systemProperties - Fact fixes: Spring DM regression fixture exception, bootstrap wrapper scope, grails-publish plugin id, skipDependencyValidation presence semantics - Agent quality bar, change workflow, expanded shared scripts and PR lessons - AGENTS.md: Boot BOM pin 4.1.x, mono-repo-integration table entry, build-logic local wrapper command Assisted-by: Sisyphus:xai/grok-4.5
Summary
Two issues prevent Gradle build cache from working for GroovyCompile, Checkstyle, and CodeNarc tasks:
GrailsGradlePlugin.configureGroovyCompiler()adds the same output file (build/grailsGroovyCompilerConfig.groovy) to everyGroovyCompiletask in a project. When a project has multipleGroovyCompiletasks (e.g.compileGroovy,compileTestGroovy,compileIntegrationTestGroovy), Gradle detects overlapping outputs and refuses to cache any of them.GrailsCodeStylePluginredirects all Checkstyle/CodeNarc XML reports torootProject.buildDir/reports/codestyle/{tool}/{project.name}.xml. Projects with multiple source sets (e.g.grails-cachehasast+main) have multiple tasks writing to the same report file, again causing overlapping outputs.Fix
grailsGroovyCompilerConfig-{taskName}.groovy) so eachGroovyCompiletask has a unique output path.{project.name}-{taskName}.xml) so each Checkstyle/CodeNarc task has a unique report location.