Repository navigation
Conversation
Since 8.3.0 (diffplug#2854) every copy of the plugin registered its build service under the same name, "SpotlessTaskService". Gradle loads a separate copy of the plugin per buildscript classloader, e.g. when sibling projects apply Spotless without a common parent. The second copy then got the first copy's service and failed with "Cannot set the value of task ... property 'taskService'". Each copy of the plugin now uses the first service name that is not taken by another copy. RegisterDependenciesTask uses the same lookup, so predeclared dependencies stay on the same service as the format tasks. Fixes diffplug#2877 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MTr23wtv6sQmXLnujeLnnP
Pankraz76
marked this pull request as ready for review
November 22, 2026 13:54
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2877
Summary
Since
8.3.0, a multi-project build fails at configuration time when Spotless is applied to sibling projects but not to their parent:Each copy of the plugin (one per buildscript classloader) now gets its own
SpotlessTaskServiceregistration. Theapply falseworkaround on the root project is no longer needed.Root cause
project-integTestvsproject-incapclassloaders. Reproduced locally, see "Tests" below.SpotlessExtensioncallsSpotlessTaskService.registerIfAbsent(project, ""), so every copy registers the build service under the same name,SpotlessTaskService.SpotlessExtension.javaBuildServiceRegistry.registerIfAbsentreturns the existing registration by name and does not check its type. The second copy therefore gets a provider for the first copy'sSpotlessTaskServiceclass, andProperty<SpotlessTaskService>.set(...)rejects it.RegisterDependenciesTasklookup failed with a cast error for the second copy, and its fallback (#1001) registered the task and the service with anidentityHashCodesuffix. #2854 removed that path from non-predeclared builds.git show f7829b55c@ServiceReference(suggested in the issue and in Gradle's hint) would not fix this. The injected service would still be an instance of another classloader's class.RegisterDependenciesTask("SpotlessTaskService" + compositeBuildSuffix) andSpotlessExtension("SpotlessTaskService") could also end up on different services in the composite-build fallback.RegisterDependenciesTask.setup()Fix
SpotlessTaskService.registerIfAbsent(Project)registers under the first name not taken by another copy of the plugin:SpotlessTaskService, thenSpotlessTaskService1, and so on.Design notes:
SpotlessTaskService.getSharedServices(),registerIfAbsent).RegisterDependenciesTasknow uses the same lookup, so it always uses the same service as theSpotlessExtensionof its own plugin copy. This removes the divergence described in finding 6. TheidentityHashCodetask-name fallback for composite builds (fix: #860 composite gradle build #1001) is unchanged.spotlessextension is created, during configuration, instead of when the first step resolves its provisioner. Configuration already did this for almost every real build (FormatExtension.provisioner(),SpotlessExtensionPredeclare). The full test suite stays green.Tests
A new
SiblingClassloaderTestputs the plugin on each subproject's own buildscript classpath and does not apply it to the root project.Two pitfalls the test has to work around:
withPluginClasspath()injects one classloader shared by all projects, which hides the bug.SpotlessTaskService.classLoaderper project.spotlessApply, thenspotlessCheck. Both projects are formatted and check passesCannot set the value of task ':b:spotlessMisc' property 'taskService'spotlessCheck --continuefails in both:a:spotlessMiscCheckand:b:spotlessMiscCheckorg.gradle.configuration-cache=true:spotlessApplytwice. The cache entry is stored, then reused, and changes are appliedChecklist
plugin-gradle/CHANGES.mdunder[Unreleased], with a link to Regression in Gradle plugin v8.3.0: Cannot set the value of task ':integTest:spotlessJava' property 'taskService' #2877plugin-gradleis affected, so noCHANGES.mdentry for lib or for plugin-maven🤖 Generated with Claude Code
https://claude.ai/code/session_01MTr23wtv6sQmXLnujeLnnP