Skip to content

Fix build cache relocatability for checkstyle:check#5067

Open
ribafish wants to merge 2 commits intohibernate:mainfrom
ribafish:fix/build-cache-checkstyle-relocatability
Open

Fix build cache relocatability for checkstyle:check#5067
ribafish wants to merge 2 commits intohibernate:mainfrom
ribafish:fix/build-cache-checkstyle-relocatability

Conversation

@ribafish
Copy link
Copy Markdown
Contributor

@ribafish ribafish commented Mar 19, 2026

Summary

checkstyle:check has 83 cache misses across all modules because the project-level <resource> in the root pom.xml points at ${rootProject.directory} (to include LICENSE.txt in META-INF). This causes the Develocity Maven extension to fingerprint the entire workspace root directory tree as a build cache input for all goals consuming project resources. After a first build, target/ directories appear under the root, changing the fingerprint and invalidating the cache for checkstyle:check in every module.

Fix: replace the resource declaration with a dedicated maven-resources-plugin:copy-resources execution.

Evidence:

JIRA: https://hibernate.atlassian.net/browse/HSEARCH-5595


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license
and can be relicensed under the terms of the LGPL v2.1 license in the future at the maintainers' discretion.
For more information on licensing, please check here.


@hibernate-github-bot
Copy link
Copy Markdown

hibernate-github-bot Bot commented Mar 19, 2026

Thanks for your pull request!

This pull request appears to follow the contribution rules.

› This message was automatically generated.

ribafish added a commit to gradle/develocity-oss-projects that referenced this pull request Mar 19, 2026
Point experiment at fork branch with the fix to validate before
applying the workaround in the experiment workflow.

Upstream PR: hibernate/hibernate-search#5067
ribafish added a commit to gradle/develocity-oss-projects that referenced this pull request Mar 19, 2026
checkstyle:check is not cache-relocatable because project resources
include ${rootProject.directory}, fingerprinting the entire workspace
root tree including target/ dirs from previous builds (83 cache misses).

Upstream PR: hibernate/hibernate-search#5067
The project-level <resource> pointing at ${rootProject.directory} (to
include LICENSE.txt in META-INF) caused the entire workspace root to be
fingerprinted as a build cache input for all goals consuming project
resources. After a first build, target/ directories appear under the
root, changing the fingerprint and causing cache misses for
checkstyle:check across all 83 modules.

Replace with a dedicated maven-resources-plugin copy-resources execution
that achieves the same result (LICENSE.txt in META-INF) without polluting
the project resource directories.
@ribafish ribafish force-pushed the fix/build-cache-checkstyle-relocatability branch from 581bb21 to c79235f Compare March 19, 2026 11:28
The HibernateSearchProcessor generates *__.java metamodel files into
target/generated-test-sources/test-annotations. Maven adds this as a
test source root, and the Develocity extension fingerprints the directory
contents as a cache input for checkstyle:check. This causes 4 cache
misses in the metamodel integration test modules because the generated
files only appear after compiler:testCompile runs.

Two fixes:
- Add **/*__.java to checkstyle excludes (skip style-checking generated code)
- Add develocity-custom-user-data.groovy to exclude **/target/** from the
  checkstyle testSourceDirectories cache input fingerprint
@ribafish ribafish force-pushed the fix/build-cache-checkstyle-relocatability branch from a1e8b3e to 0a07a9c Compare March 19, 2026 12:19
Copy link
Copy Markdown
Member

@marko-bekhta marko-bekhta left a comment

Choose a reason for hiding this comment

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

Hey 👋🏻 🙂

Thanks for the PR! Hm that's an interesting finding.

Comment on lines +1 to +9
buildCache.registerMojoMetadataProvider(context -> {
context.withPlugin("maven-checkstyle-plugin", () -> {
context.inputs(inputs -> {
inputs.fileSet("testSourceDirectories", fileSet ->
fileSet.excludes("**/target/**")
)
})
})
})
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

we have https://github.com/hibernate/hibernate-develocity-maven-extension for these. would you want to move it there ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hey 👋🏻
I've moved this registration to: hibernate/hibernate-develocity-maven-extension#86

btw why do we exclude target for the test sources only ? (would be nice to have a comment with the reasoning in the code so we won't be guessing what happened in a future 🙂)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hey, I had a plan to do this today but you beat me to it :)

The checkstyle plugin has two file set inputs: sourceDirectories and testSourceDirectories. The problem is specific to test sources because:

Hibernate Search's annotation processor (HibernateSearchProcessor) generates *__.java metamodel files into target/generated-test-sources/test-annotations. This isn't explicitly configured anywhere — it's the default behavior of maven-compiler-plugin when running testCompile
with <proc>full</proc> and the annotation processor (configured in integration test modules like integrationtest/metamodel/orm-lucene/pom.xml). The processor uses the standard Filer API, and Maven automatically directs annotation processor output during test compilation to
that default path. Maven then adds that directory as a test source root, which is how it ends up in checkstyle's testSourceDirectories input.

When Develocity fingerprints testSourceDirectories for checkstyle:check, it picks up target/generated-test-sources/... contents — which only exist after compiler:testCompile runs, making the fingerprint unstable across builds.

Main sourceDirectories don't have this problem — no generated sources under target/ are added as main source roots in those modules.

That's also why the fix in the hibernate-search PR has two parts: the **/target/** exclusion from cache inputs (so generated test sources don't affect the fingerprint), and the **/*__.java checkstyle exclude (so checkstyle doesn't style-check generated code).

That being said, you could also exclude **/target/** for sourceDirectories, there should be no impact there.

@sonarqubecloud
Copy link
Copy Markdown

ribafish added a commit to gradle/develocity-oss-projects that referenced this pull request Mar 27, 2026
Point experiment at fork branch with the fix to validate before
applying the workaround in the experiment workflow.

Upstream PR: hibernate/hibernate-search#5067
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants