Skip to content

Support P2/Maven formatter predeclaration with configuration cache - #3211

Open
bric3 wants to merge 5 commits into
diffplug:mainfrom
bric3:greclipse-predeclare-configuration-cache
Open

bric3 wants to merge 5 commits into
diffplug:mainfrom
bric3:greclipse-predeclare-configuration-cache

Conversation

@bric3

@bric3 bric3 commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

greclipse() can fail while Gradle stores the configuration cache when its dependencies are declared through spotlessPredeclare.

1 problem was found storing the configuration cache.
- Task `:sub:spotlessGroovy` of type `com.diffplug.gradle.spotless.SpotlessTaskImpl`: error writing value of type 'com.diffplug.spotless.ConfigurationCacheHackList'

> P2 dependencies not predeclared. Add Eclipse formatter configuration to the `spotlessPredeclare` block in the root project.

Configuration cache entry discarded due to serialization error.

Under the hood, unlazy() skips roundtrip formatter steps, leaving their dependencies unresolved when subproject steps are serialized. This PR makes resolution of the predeclared formatter steps in the root project when the task graph is ready and a Spotless task is scheduled, before Gradle actually stores things in the configuration cache. This also covers other Maven/P2 formatters and steps nested inside withinBlocks

Move predeclaration from afterEvaluate to taskGraph.whenReady. The closures inside spotlessPredeclare will now run when the task graph is ready, provided the dependency registration task is scheduled. Spotless tasks bring that task into the graph; unrelated tasks such as help skip provisioning.

The multi-project regressions cover parallel cache storage; the single-project regressions cover cache reuse.

This should fix also #2459


Please DO NOT FORCE PUSH. Don't worry about messy history, it's easier to do code review if we can tell what happened after the review, and force pushing breaks that.

Please make sure that your PR allows edits from maintainers. Sometimes it's faster for us to just fix something than it is to describe how to fix it.

Allow edits from maintainers

After creating the PR, please add a commit that adds a bullet-point under the [Unreleased] section of CHANGES.md, plugin-gradle/CHANGES.md, and plugin-maven/CHANGES.md which includes:

  • a summary of the change
  • either
    • a link to the issue you are resolving (for small changes)
    • a link to the PR you just created (for big changes likely to have discussion)

If your change only affects a build plugin, and not the lib, then you only need to update the plugin-foo/CHANGES.md for that plugin.

If your change affects lib in an end-user-visible way (fixing a bug, updating a version) then you need to update CHANGES.md for both the lib and all build plugins. Users of a build plugin shouldn't have to refer to lib to see changes that affect them.

This makes it easier for the maintainers to quickly release your changes :)

@bric3 bric3 changed the title fix: support formatter predeclaration with configuration cache Support P2/Maven formatter predeclaration with configuration cache Nov 26, 2026
@bric3
bric3 marked this pull request as ready for review November 26, 2026 22:56
@bric3

bric3 commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Seems like the failing jobs are related to Maven Central, replaying with the 429 status 🥺

https://github.com/diffplug/spotless/actions/runs/45907856196/job/140209248798?pr=3211#step:5:52

This branch has not been deployed

No deployments
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.

1 participant