question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot add a configuration with name 'classpath' as a configuration with that name already exists (intermittent plugin-gradle concurrency bug)

See original GitHub issue

Hi, we just had a spurious error on our jenkins after upgrading our spotless gradle plugin to 3.18 due to “org.gradle.api.InvalidUserDataException: Cannot add a configuration with name ‘classpath’ as a configuration with that name already exists.” This is for a multiproject build with parallel execution and it seems that gradle tries to create the classpath configuration multiple times in DefaultScriptHandler. Seeing as there are no locks in this code, I’m guessing that defineConfiguration() is not meant to be called in parallel but somehow it is being called that way.

Also the error message printed to the log about missing repos is a bit confusing due to GradleProvisioner catching Exception and printing a error message that’s better suited for catching ResolveException. I first troubleshooting thought was to go to our artifactory and check our logs (it sent the files correctly).

Gradle 5.2.1, Spotless gradle plugin 3.18, Ubuntu 16.04 docker container.

buildSrc/build.gradle
=====================

repositories {
  maven {
    url 'https://ourartifactory.stuff/mvn'
    credentials {
      username = artifactory_user
      password = artifactory_password
    }
  }
}
dependencies {
  compile "com.diffplug.spotless:spotless-plugin-gradle:3.18.0" // Use of buildSrc to infer repositories/dependencies to all build scripts
}


build.gradle
============
allprojects {
  pluginManager.withPlugin('java') {
    apply plugin: "com.diffplug.gradle.spotless"
    spotless {
      // See https://github.com/diffplug/spotless/tree/master/plugin-gradle for configuration
      java {
        target 'src/**/*.java' // Only format checked in code, not generated sources        
        removeUnusedImports() // removes any unused imports
        eclipse('4.9.0').configFile "$rootDir/utils/.settings/org.eclipse.jdt.core.prefs"
      }
    }
    tasks.withType(JavaCompile)*.dependsOn 'spotlessApply'    
  }
}
07:42:47  > Task :SubProj1:spotlessJava
07:42:47  You probably need to add a repository containing the '[com.google.googlejavaformat:google-java-format:1.7]' artifact in the 'build.gradle' of your root project.
07:42:47  E.g.: 'buildscript { repositories { mavenCentral() }}'
07:42:47  Note that included buildscripts (using 'apply from') do not share their buildscript repositories with the underlying project.
07:42:47  You have to specify the missing repository explicitly in the buildscript of the root project.
07:42:47  
07:42:47  org.gradle.api.InvalidUserDataException: Cannot add a configuration with name 'classpath' as a configuration with that name already exists.
07:42:47  	at org.gradle.api.internal.DefaultNamedDomainObjectCollection.assertCanAdd(DefaultNamedDomainObjectCollection.java:212)
07:42:47  	at org.gradle.api.internal.AbstractNamedDomainObjectContainer.create(AbstractNamedDomainObjectContainer.java:93)
07:42:47  	at org.gradle.api.internal.AbstractValidatingNamedDomainObjectContainer.create(AbstractValidatingNamedDomainObjectContainer.java:46)
07:42:47  	at org.gradle.api.internal.AbstractNamedDomainObjectContainer.create(AbstractNamedDomainObjectContainer.java:75)
07:42:47  	at org.gradle.api.internal.initialization.DefaultScriptHandler.defineConfiguration(DefaultScriptHandler.java:111)
07:42:47  	at org.gradle.api.internal.initialization.DefaultScriptHandler.getConfigurations(DefaultScriptHandler.java:101)
07:42:47  	at com.diffplug.gradle.spotless.GradleProvisioner.lambda$fromProject$1(GradleProvisioner.java:40)
07:42:47  	at com.diffplug.spotless.JarState.provisionWithTransitives(JarState.java:87)
07:42:47  	at com.diffplug.spotless.JarState.from(JarState.java:76)
07:42:47  	at com.diffplug.spotless.JarState.from(JarState.java:71)
07:42:47  	at com.diffplug.spotless.java.GoogleJavaFormatStep$State.<init>(GoogleJavaFormatStep.java:99)
07:42:47  	at com.diffplug.spotless.java.GoogleJavaFormatStep$State.<init>(GoogleJavaFormatStep.java:95)
07:42:47  	at com.diffplug.spotless.java.RemoveUnusedImportsStep.lambda$create$0(RemoveUnusedImportsStep.java:33)
07:42:47  	at com.diffplug.spotless.FormatterStepImpl.calculateState(FormatterStepImpl.java:56)
07:42:47  	at com.diffplug.spotless.LazyForwardingEquality.state(LazyForwardingEquality.java:56)
07:42:47  	at com.diffplug.spotless.LazyForwardingEquality.writeObject(LazyForwardingEquality.java:68)
07:42:47  	at sun.reflect.GeneratedMethodAccessor535.invoke(Unknown Source)
07:42:47  	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
07:42:47  	at java.lang.reflect.Method.invoke(Method.java:498)
07:42:47  	at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:1128)
07:42:47  	at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1496)
07:42:47  	at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)
07:42:47  	at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
07:42:47  	at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)
07:42:47  	at org.gradle.internal.snapshot.impl.DefaultValueSnapshotter.serialize(DefaultValueSnapshotter.java:180)
07:42:47  	at org.gradle.internal.snapshot.impl.DefaultValueSnapshotter.processValue(DefaultValueSnapshotter.java:172)
07:42:47  	at org.gradle.internal.snapshot.impl.DefaultValueSnapshotter.snapshot(DefaultValueSnapshotter.java:59)
07:42:47  	at org.gradle.internal.snapshot.ValueSnapshotStrategy.snapshot(ValueSnapshotStrategy.java:30)
07:42:47  	at org.gradle.internal.snapshot.impl.DefaultValueSnapshotter.processValue(DefaultValueSnapshotter.java:99)
07:42:47  	at org.gradle.internal.snapshot.impl.DefaultValueSnapshotter.snapshot(DefaultValueSnapshotter.java:59)
07:42:47  	at org.gradle.api.internal.tasks.execution.ResolveBeforeExecutionStateTaskExecuter.snapshotTaskInputProperties(ResolveBeforeExecutionStateTaskExecuter.java:124)
07:42:47  	at org.gradle.api.internal.tasks.execution.ResolveBeforeExecutionStateTaskExecuter.createExecutionState(ResolveBeforeExecutionStateTaskExecuter.java:90)
07:42:47  	at org.gradle.api.internal.tasks.execution.ResolveBeforeExecutionStateTaskExecuter.execute(ResolveBeforeExecutionStateTaskExecuter.java:72)
07:42:47  	at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
07:42:47  	at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:109)
07:42:47  	at org.gradle.api.internal.tasks.execution.ResolveBeforeExecutionOutputsTaskExecuter.execute(ResolveBeforeExecutionOutputsTaskExecuter.java:67)
07:42:47  	at org.gradle.api.internal.tasks.execution.ResolveAfterPreviousExecutionStateTaskExecuter.execute(ResolveAfterPreviousExecutionStateTaskExecuter.java:46)
07:42:47  	at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:93)
07:42:47  	at org.gradle.api.internal.tasks.execution.FinalizePropertiesTaskExecuter.execute(FinalizePropertiesTaskExecuter.java:45)
07:42:47  	at org.gradle.api.internal.tasks.execution.ResolveTaskExecutionModeExecuter.execute(ResolveTaskExecutionModeExecuter.java:94)
07:42:47  	at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:57)
07:42:47  	at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:56)
07:42:47  	at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:36)
07:42:47  	at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.executeTask(EventFiringTaskExecuter.java:63)
07:42:47  	at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:49)
07:42:47  	at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:46)
07:42:47  	at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:416)
07:42:47  	at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:406)
07:42:47  	at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:165)
07:42:47  	at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:250)
07:42:47  	at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:158)
07:42:47  	at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:102)
07:42:47  	at org.gradle.internal.operations.DelegatingBuildOperationExecutor.call(DelegatingBuildOperationExecutor.java:36)
07:42:47  	at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter.execute(EventFiringTaskExecuter.java:46)
07:42:47  	at org.gradle.execution.plan.LocalTaskNodeExecutor.execute(LocalTaskNodeExecutor.java:43)
07:42:47  	at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:355)
07:42:47  	at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:343)
07:42:47  	at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:336)
07:42:47  	at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:322)
07:42:47  	at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker$1.execute(DefaultPlanExecutor.java:134)
07:42:47  	at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker$1.execute(DefaultPlanExecutor.java:129)
07:42:47  	at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.execute(DefaultPlanExecutor.java:202)
07:42:47  	at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.executeNextNode(DefaultPlanExecutor.java:193)
07:42:47  	at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.run(DefaultPlanExecutor.java:129)
07:42:47  	at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
07:42:47  	at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
07:42:47  	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
07:42:47  	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
07:42:47  	at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
07:42:47  	at java.lang.Thread.run(Thread.java:748)
07:42:47  

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:33 (17 by maintainers)

github_iconTop GitHub Comments

1reaction
vlsicommented, Oct 2, 2019

What is unsafe about it?

It seems to defeat Gradle Build Scan as well (however they seem to agree to fix that):

https://discuss.gradle.org/t/your-build-scan-could-not-be-displayed-what-does-this-mean/33302/10

1reaction
uklancecommented, Mar 27, 2019

I’ll not be contributing such a fix so I think your duct tape wins. I’d argue

synchronized (project.getRootProject()) {...} 

Is slightly better than

synchronized (GradleProvisioner.class) {...} 
Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot add a configuration with name 'testCompile' as a ...
To fix that issue i did the following: Added the following to my build gradle script: apply plugin: 'org.robolectric' dependencies { classpath ......
Read more >
Spotless issue 373: Cannot add a configuration with name ...
I believe this line: Configuration config = project.getRoot… ... with name 'classpath' as a configuration with that name already exists.
Read more >
Gradle Enterprise Gradle Plugin User Manual
Failed background build scan uploads; Slow resolution of host name; Late application; Using the Configuration Cache.
Read more >
Spring Boot Gradle Plugin Reference Guide
First, configure the project to depend on the Spring Boot plugin but do not apply it: ... tasks.named("bootWar") { classpath configurations.
Read more >
Gradle Plugin User Guide - Android Studio Project Site
3 Dependencies, Android Libraries and Multi-project setup ... This means the Build Type names cannot be main or androidTest (this is enforced by...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found