Spotless prevents to build or import
I cloned the repo, and I see this error when trying to build or when importing in IJ and this is very confusing because at first nothing looks wrong.
Cannot change dependencies of dependency configuration ':jsvg:compileOnly' after it has been included in dependency resolution.
$ ./gradlew build
Type-safe project accessors is an incubating feature.
Project accessors enabled, but root project name not explicitly set for 'buildSrc'. Checking out the project in different folders will impact the generated code and implicitly the buildscript classpath, breaking caching.
> Configure project :
Building: JSVG 1.5.0-SNAPSHOT
JDK: /Users/brice.dutheil/.asdf/installs/java/corretto-17.0.10.7.1
Gradle: 8.3
Build jsvg-root FAILURE reason:
org.gradle.internal.exceptions.LocationAwareException: Build file '/Users/brice.dutheil/opensource/jsvg/jsvg/build.gradle.kts' line: 11
Cannot change dependencies of dependency configuration ':jsvg:compileOnly' after it has been included in dependency resolution.
Caused by: org.gradle.api.InvalidUserDataException: Cannot change dependencies of dependency configuration ':jsvg:compileOnly' after it has been included in dependency resolution.
at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration.preventIllegalMutation(DefaultConfiguration.java:1520)
at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration.validateMutation(DefaultConfiguration.java:1479)
at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration.lambda$validateMutationType$0(DefaultConfiguration.java:358)
at org.gradle.internal.ImmutableActionSet$SingletonSet.execute(ImmutableActionSet.java:225)
at org.gradle.api.internal.DefaultDomainObjectSet.assertMutableCollectionContents(DefaultDomainObjectSet.java:57)
at org.gradle.api.internal.DefaultDomainObjectCollection.addLater(DefaultDomainObjectCollection.java:272)
at org.gradle.api.internal.DelegatingDomainObjectSet.addLater(DelegatingDomainObjectSet.java:104)
at org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.doAddProvider(DefaultDependencyHandler.java:218)
at org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.doAdd(DefaultDependencyHandler.java:191)
at org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.add(DefaultDependencyHandler.java:123)
at org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.add(DefaultDependencyHandler.java:117)
at org.gradle.kotlin.dsl.support.delegates.DependencyHandlerDelegate.add(DependencyHandlerDelegate.kt:53)
at Build_gradle$1.invoke(build.gradle.kts:11)
at Build_gradle$1.invoke(build.gradle.kts:10)
at org.gradle.kotlin.dsl.ProjectExtensionsKt.dependencies(ProjectExtensions.kt:236)
at Build_gradle.<init>(build.gradle.kts:10)
at org.gradle.kotlin.dsl.execution.Interpreter$ProgramHost.eval(Interpreter.kt:523)
at org.gradle.kotlin.dsl.execution.Interpreter$ProgramHost.evaluateSecondStageOf(Interpreter.kt:451)
at org.gradle.kotlin.dsl.execution.Interpreter$ProgramHost.eval(Interpreter.kt:523)
at org.gradle.kotlin.dsl.execution.Interpreter.eval(Interpreter.kt:218)
...
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/brice.dutheil/opensource/jsvg/jsvg/build.gradle.kts' line: 11
* What went wrong:
Cannot change dependencies of dependency configuration ':jsvg:compileOnly' after it has been included in dependency resolution.
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.
Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
For more on this, please refer to https://docs.gradle.org/8.3/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.
BUILD FAILED in 4s
4 actionable tasks: 4 up-to-date
After various trial and errors I found out that spotless was the culprit, and that it is required to add skipSpotless = true in properties.
And running also run into the same issue.
$ ./gradlew spotlessCheck -PspotlessRatchet=false -PskipSpotless=false
Also, contributing mention an autostyleCheck task but it doesn't exist.
Ever task with a name containing autostyle has been replaced by a version with spotless with it. Looks like I never got around to updating it in the documentation.
Not sure about the error though. I will try to reproduce it.
Ah, I forgot I had this in my ./gradle/init.d folder, not sure why it cause this issue though.
auto-apply-spotless
allprojects {
plugins.withType(JavaPlugin::class.java) {
plugins.withId("com.diffplug.spotless") {
tasks.findByName("spotlessApply")?.let { spotless ->
tasks.withType<JavaCompile> { // this causes the issue
finalizedBy(spotless)
}
}
}
// legacy plugin id
plugins.withId("com.diffplug.gradle.spotless") {
tasks.findByName("spotlessApply")?.let { spotless ->
tasks.withType<JavaCompile> {
finalizedBy(spotless)
}
}
}
}
}
Interesting. Maybe I can figure out why it’s causing the error. Though I don’t immediately see why it should be an issue.
Yep I don't see as well why it could be an issue there, these seem to be different tasks.
For now I disabled this in my init.d which allows the project to be imported fine.