- Notifications
You must be signed in to change notification settings - Fork 493
Description
Situation: Our build is using Gradles dependencyResolutionManagement feature to centralize repository configuration in a multi-project setup. This involves setting up the list of repositories in settings.gradle. Please note that declaring any repository in a subproject will make that subproject ignore the centralized configuration completely, which is why we set repositoriesMode = RepositoriesMode.FAIL_ON_PROJECT_REPOS.
Bug: When adding biome() to the spotless configuration, it will internally add mavenLocal() to the project temporarily to determine a suitable download directory. This sadly causes the Gradle validation to trip and crash the build with the following stack trace:
The exception is:
[...] Caused by: org.gradle.api.InvalidUserCodeException: Build was configured to prefer settings repositories over project repositories but repository 'MavenLocal' was added by build file 'build.gradle' at org.gradle.internal.management.DefaultDependencyResolutionManagement.repoMutationDisallowedOnProject(DefaultDependencyResolutionManagement.java:199) at org.gradle.internal.ImmutableActionSet$SetWithFewActions.execute(ImmutableActionSet.java:285) at org.gradle.api.internal.DefaultDomainObjectCollection.doAdd(DefaultDomainObjectCollection.java:262) at org.gradle.api.internal.DefaultNamedDomainObjectCollection.doAdd(DefaultNamedDomainObjectCollection.java:125) at org.gradle.api.internal.DefaultDomainObjectCollection.add(DefaultDomainObjectCollection.java:251) at org.gradle.api.internal.artifacts.DefaultArtifactRepositoryContainer.access$101(DefaultArtifactRepositoryContainer.java:35) at org.gradle.api.internal.artifacts.DefaultArtifactRepositoryContainer.lambda$new$0(DefaultArtifactRepositoryContainer.java:38) at org.gradle.api.internal.artifacts.DefaultArtifactRepositoryContainer.addWithUniqueName(DefaultArtifactRepositoryContainer.java:101) at org.gradle.api.internal.artifacts.DefaultArtifactRepositoryContainer.addRepository(DefaultArtifactRepositoryContainer.java:89) at org.gradle.api.internal.artifacts.DefaultArtifactRepositoryContainer.addRepository(DefaultArtifactRepositoryContainer.java:84) at org.gradle.api.internal.artifacts.dsl.DefaultRepositoryHandler.mavenLocal(DefaultRepositoryHandler.java:142) at com.diffplug.gradle.spotless.RomeStepConfig.findDataDir(RomeStepConfig.java:216) at com.diffplug.gradle.spotless.RomeStepConfig.resolveDownloadDir(RomeStepConfig.java:276) at com.diffplug.gradle.spotless.RomeStepConfig.newBuilder(RomeStepConfig.java:242) at com.diffplug.gradle.spotless.RomeStepConfig.createStep(RomeStepConfig.java:161) at com.diffplug.gradle.spotless.JsonExtension.biome(JsonExtension.java:75) at com.diffplug.gradle.spotless.JsonExtension.biome(JsonExtension.java:69) at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) at org.gradle.internal.metaobject.BeanDynamicObject$MetaClassAdapter.invokeMethod(BeanDynamicObject.java:541) at org.gradle.internal.metaobject.BeanDynamicObject.tryInvokeMethod(BeanDynamicObject.java:218) at org.gradle.internal.metaobject.CompositeDynamicObject.tryInvokeMethod(CompositeDynamicObject.java:99) at org.gradle.internal.extensibility.MixInClosurePropertiesAsMethodsDynamicObject.tryInvokeMethod(MixInClosurePropertiesAsMethodsDynamicObject.java:38) at org.gradle.internal.metaobject.ConfigureDelegate.invokeMethod(ConfigureDelegate.java:65) at build_bucleb6i2fo8z9yql3xzqbyv3$_run_closure19$_closure61.doCall$original(C:\AE2\Forge\build.gradle:424) Here is a minimal build.gradle / settings.gradle to reproduce this problem:
build.gradle
plugins { id 'com.diffplug.spotless' version '6.25.0' } spotless { json { biome() } }settings.gradle
dependencyResolutionManagement { repositoriesMode = RepositoriesMode.FAIL_ON_PROJECT_REPOS repositories { mavenCentral() } }We are currently working around this problem by avoiding biome() and manually constructing the step, configuring the downloadDir (we have to catch the exception when it tries to replace the non-existent step), and then adding the step.
What this would need in Spotless is either a different approach to selecting a download directory altogether, or at least the ability to customize the BiomeStepConfig before the step is actually created, without throwing exceptions.
- Gradle or Maven version: Gradle 8.8
- spotless version: 6.25.0
- operating system and version: Windows 11