Skip to content

Fix overlapping task outputs preventing build cache usage - #15532

Merged
matrei merged 4 commits into
apache:7.0.xfrom
ribafish:fix-overlapping-task-outputs
Mar 27, 2026
Merged

matrei merged 4 commits into
apache:7.0.xfrom
ribafish:fix-overlapping-task-outputs

Conversation

@ribafish

Copy link
Copy Markdown
Contributor

Summary

Two issues prevent Gradle build cache from working for GroovyCompile, Checkstyle, and CodeNarc tasks:

  1. 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.

  2. GrailsCodeStylePlugin redirects all Checkstyle/CodeNarc XML reports to rootProject.buildDir/reports/codestyle/{tool}/{project.name}.xml. Projects with multiple source sets (e.g. grails-cache has ast + main) have multiple tasks writing to the same report file, again causing overlapping outputs.

Fix

  • Use task-specific config file names (grailsGroovyCompilerConfig-{taskName}.groovy) so each GroovyCompile task has a unique output path.
  • Include the task name in report file paths ({project.name}-{taskName}.xml) so each Checkstyle/CodeNarc task has a unique report location.

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.
ribafish added a commit to gradle/develocity-oss-projects that referenced this pull request Mar 25, 2026
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
@jdaugherty

Copy link
Copy Markdown
Contributor

@ribafish Good catch! Thank you for your contribution. @matrei

@matrei matrei left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you @ribafish

@testlens-app

This comment has been minimized.

@ribafish
ribafish marked this pull request as draft March 26, 2026 12:32
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.
@ribafish

Copy link
Copy Markdown
Contributor Author

Added two more commits on top of the overlapping outputs fix:

Normalize APP_BASE_DIR system property — configureForkSettings() 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, this absolute path becomes part of the cache key and prevents cache hits when building from a different directory. Replaced with a CommandLineArgumentProvider using @PathSensitive(RELATIVE).

Make SBOM timestamp reproducible — The CycloneDX SBOM rewrite uses buildDate (defaults to Instant.now() without SOURCE_DATE_EPOCH) for the metadata timestamp, which also changes the serialNumber UUID. Since the SBOM is embedded in every jar, this cascades cache misses through the compile classpath of downstream projects. Fixed by using Instant.EPOCH when SOURCE_DATE_EPOCH is not set. Release builds continue to use the real build date.

Remaining: SourceTask path sensitivity — GroovyCompile, Checkstyle, CodeNarc, and Groovydoc tasks still have relocatability issues in experiment 3 (validates local build caching by building the same commit from two different checkout directories and verifying cache hits on the second build). This happens because SourceTask.getSource() defaults to @PathSensitive(ABSOLUTE) in Gradle itself, which cannot be fixed in grails-core. Additionally, since grails-gradle is an included build compiled from Groovy, the task implementation bytecode differs between directories (Groovy compiler embeds source paths), causing "Task implementation changed" for all tasks whose class originates from the included build. This is a known limitation of experiment 3 with Groovy-compiled included builds.

@ribafish
ribafish marked this pull request as ready for review March 26, 2026 14:03
@ribafish
ribafish requested a review from matrei March 26, 2026 14:03
@testlens-app

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.
@testlens-app

testlens-app Bot commented Mar 26, 2026 •

Copy link
Copy Markdown

✅ All tests passed ✅

🏷️ Commit: a5b18b2
▶️ Tests: 34099 executed
⚪️ Checks: 31/31 completed


Learn more about TestLens at testlens.app.

* by their respective tasks.
*/
@CompileStatic
class GrailsAppBaseDirProvider implements CommandLineArgumentProvider {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@bito-code-review

Copy link
Copy Markdown

This question isn’t related to the pull request. I can only help with questions about the PR’s code or comments.

@jdaugherty jdaugherty left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matrei Can you please check this out one more time? If you agree, I'll merge.

@matrei matrei left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thank you!

@matrei
matrei merged commit 5d885bf into apache:7.0.x Mar 27, 2026
32 checks passed
@jdaugherty

Copy link
Copy Markdown
Contributor

@ribafish I opened gradle/gradle#38395 - apparently sometime between the latest gradle release and gradle 8, this stopped working as i would expect. =(

jamesfredley added a commit that referenced this pull request Aug 5, 2026
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants