Repository navigation
Closed
Labels
Description
We occasionally see this error in our elasticsearch build:
The :spotlessInternalRegisterDependencies task failed.
Cannot add a configuration with name 'spotless-1911100560' as a configuration with that name already exists
The according stack trace:
* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':spotlessInternalRegisterDependencies'.
at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:38)
at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.executeTask(EventFiringTaskExecuter.java:77)
at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:55)
at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:52)
at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:200)
at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:195)
at org.gradle.internal.operations.DefaultBuildOperationRunner$3.execute(DefaultBuildOperationRunner.java:75)
at org.gradle.internal.operations.DefaultBuildOperationRunner$3.execute(DefaultBuildOperationRunner.java:68)
at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:153)
at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:68)
at org.gradle.internal.operations.DefaultBuildOperationRunner.call(DefaultBuildOperationRunner.java:62)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.lambda$call$2(DefaultBuildOperationExecutor.java:79)
at org.gradle.internal.operations.UnmanagedBuildOperationWrapper.callWithUnmanagedSupport(UnmanagedBuildOperationWrapper.java:54)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:79)
at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter.execute(EventFiringTaskExecuter.java:52)
at org.gradle.execution.plan.LocalTaskNodeExecutor.execute(LocalTaskNodeExecutor.java:74)
at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:408)
at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:395)
at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:388)
at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:374)
at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.lambda$run$0(DefaultPlanExecutor.java:127)
at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.execute(DefaultPlanExecutor.java:191)
at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.executeNextNode(DefaultPlanExecutor.java:182)
at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.run(DefaultPlanExecutor.java:124)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
at java.base/java.lang.Thread.run(Thread.java:831)
Caused by: org.gradle.api.InvalidUserDataException: Cannot add a configuration with name 'spotless-1911100560' as a configuration with that name already exists.
at org.gradle.api.internal.DefaultNamedDomainObjectCollection.assertCanAdd(DefaultNamedDomainObjectCollection.java:213)
at org.gradle.api.internal.AbstractNamedDomainObjectContainer.create(AbstractNamedDomainObjectContainer.java:77)
at org.gradle.api.internal.AbstractValidatingNamedDomainObjectContainer.create(AbstractValidatingNamedDomainObjectContainer.java:47)
at org.gradle.api.internal.AbstractNamedDomainObjectContainer.create(AbstractNamedDomainObjectContainer.java:56)
at com.diffplug.gradle.spotless.GradleProvisioner.lambda$fromRootBuildscript$0(GradleProvisioner.java:66)
at com.diffplug.gradle.spotless.GradleProvisioner$RootProvisioner.provisionWithTransitives(GradleProvisioner.java:55)
at com.diffplug.spotless.JarState.provisionWithTransitives(JarState.java:68)
at com.diffplug.spotless.JarState.withoutTransitives(JarState.java:62)
at com.diffplug.spotless.extra.EclipseBasedStepBuilder$State.<init>(EclipseBasedStepBuilder.java:155)
at com.diffplug.spotless.extra.EclipseBasedStepBuilder.get(EclipseBasedStepBuilder.java:132)
at com.diffplug.spotless.FormatterStepImpl.calculateState(FormatterStepImpl.java:56)
at com.diffplug.spotless.LazyForwardingEquality.state(LazyForwardingEquality.java:56)
at com.diffplug.spotless.LazyForwardingEquality.toBytes(LazyForwardingEquality.java:85)
at com.diffplug.spotless.LazyForwardingEquality.hashCode(LazyForwardingEquality.java:102)
at java.base/java.lang.Object.toString(Object.java:238)
at java.base/java.lang.String.valueOf(String.java:3365)
at java.base/java.lang.StringBuilder.append(StringBuilder.java:169)
at java.base/java.util.AbstractCollection.toString(AbstractCollection.java:457)
at java.base/java.util.Formatter$FormatSpecifier.printString(Formatter.java:3050)
at java.base/java.util.Formatter$FormatSpecifier.print(Formatter.java:2927)
at java.base/java.util.Formatter.format(Formatter.java:2689)
at java.base/java.util.Formatter.format(Formatter.java:2625)
at java.base/java.lang.String.format(String.java:3290)
at org.gradle.internal.execution.fingerprint.impl.DefaultInputFingerprinter$InputCollectingVisitor.visitInputProperty(DefaultInputFingerprinter.java:99)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$TaskExecution.visitRegularInputs(ExecuteActionsTaskExecuter.java:311)
at org.gradle.internal.execution.fingerprint.impl.DefaultInputFingerprinter.fingerprintInputProperties(DefaultInputFingerprinter.java:52)
at org.gradle.internal.execution.steps.CaptureStateBeforeExecutionStep.captureExecutionState(CaptureStateBeforeExecutionStep.java:170)
at org.gradle.internal.execution.steps.CaptureStateBeforeExecutionStep.lambda$captureExecutionStateOp$1(CaptureStateBeforeExecutionStep.java:126)
at org.gradle.internal.execution.steps.BuildOperationStep$1.call(BuildOperationStep.java:37)
at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:200)
- We use spotless 5.12.5 but looking at the changelog nothing in that area has changed in newer versions.
- We use gradle 7.2
- fails on Linux (CentOs7 & 8 and Windows)
The issue was initially raised in the elasticsearch issue tracker at: elastic/elasticsearch#77837
The source is available at https://github.com/elastic/elasticsearch
Looking into this bug I noticed that moving away from detached configurations in GradleProvisioner#fromRootBuildscript introduced this issue. It seems like either an issue with the caching of the Requests or a problem with parallel execution (though I'm not sure how that could happen here with the current gradle behaviour)
Maybe using maybeCreate instead of create for getting the configuration is enough here for now. Happy to create a Pull Request with that change.
Activity
nedtwigg commentedon Sep 20, 2021
It's hard to confirm whether an intermittent issue is fixed, but I think this is fixed in
plugin-gradle 5.15.1by #942. Please let me know if this issue reoccurs for you. We have a deeper fix coming in the future with #721.breskeby commentedon Sep 20, 2021
Thanks @nedtwigg for the quick response. I'll update our build tomorrow and then I'll keep an eye on this the next few days!
Thanks again, highly appreciated
Update spotless plugin to contain race condition fix
Update spotless plugin to contain race condition fix (#78062)
Update spotless plugin to contain race condition fix (elastic#78062)
Update spotless plugin to contain race condition fix (#78062) (#78066)
breskeby commentedon Oct 1, 2021
@nedtwigg even with the latest snapshot version we now saw this failure happening unfortunately. seems the fix isn't 100% working. should we reopen this?
nedtwigg commentedon Oct 1, 2021
Bummer. Same
Cannot add a configuration with name 'spotless-1911100560' as a configuration with that name already exists., or is the error message new?jbduncan commentedon Oct 1, 2021
I guess the problem is still that the cache is being accessed concurrently. If so, we have a few possible fixes:
GradleProvisioner::provisionWithTransitivesin asynchronized (cache) { ... }block.com.diffplug.durian:durian-cacheand use a cache from there. We probably don't need anything as polished and performant as Caffeine's cache.nedtwigg commentedon Oct 1, 2021
I think we probably won't be able to get any further with more
synchronizedblocks.I think we need to do one of two things (could maybe do both)
Stop resolving dependencies from the buildscript repositories (seems to be a mostly dead concept now anyway) which lets us resolve dependencies independently in every subproject. I am not 100% sure that this actually works because of the delayed way that we define dependencies and also the special rules you can get away with only in the root project.
Require users to proactively declare every step that they use in the root project, which allows us to eagerly declare those configurations in a normal gradle-happy way, but still reuse them in subprojects. A subproject which requests a non-existent configuration can fail with a nice friendly error message describing what needs to happen. This can definitely work.
Solution 2 would look like so:
This extension would only be valid in the root project, it wouldn't have a target, and it would create all the configurations used in all subprojects. When a subproject requested a formatter which the root project didn't have, it would throw an error with a suggested fix to
spotlessRoot. I think this might also fix parts of our configuration cache issues (#644). But it requires user input, which is a bummer.I think we could maybe do both. Do 1 to fix this issue, but we'll be slow and configuration cache still won't work, and then later users have the option to speed up their builds and add configuration-cache support with 2. Actually doing this is a big project and it's not gonna make the top of my todo, but I'm happy to coach someone who wants to take a whack at it.
skagedal commentedon Nov 6, 2021
Hi! Is there any known workaround for this? I.e., getting Spotless to run at all with current version of Gradle. I don't know if it helps, but here is the build.gradle of a small example project where I get this issue every time I run
./gradlew build.Gradle output
nedtwigg commentedon Nov 6, 2021
Thanks for the example @skagedal. We've put this off too long, I'm digging in now.
nedtwigg commentedon Nov 7, 2021
The two PRs above allow us to sidestep the synchronization issue entirely, which will hopefully resolve this one and for all. It is a breaking change though, and will require a little bit of integration effort. I'll post back when they are merged and ready to use.
nedtwigg commentedon Nov 9, 2021
I believe these issues are all resolved in plugin-gradle 6.0.0, see release notes for details. Please reopen if the issue re-appears.
skagedal commentedon Nov 9, 2021
Seems to work great, thank you very much! Now running into the next issue, but I'll comment there instead if needed. :)
Update spotless plugin to contain race condition fix (#78062)