Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON Biome Step breaks Gradle Dependency Resolution Management #2187

Closed
3 tasks done
shartte opened this issue Jun 26, 2024 · 1 comment · Fixed by #2260
Closed
3 tasks done

JSON Biome Step breaks Gradle Dependency Resolution Management #2187

shartte opened this issue Jun 26, 2024 · 1 comment · Fixed by #2260
Labels

Comments

@shartte
Copy link

shartte commented Jun 26, 2024

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
@nedtwigg nedtwigg added the bug label Jul 4, 2024
blutorange pushed a commit to blutorange/spotless that referenced this issue Sep 12, 2024
…2187

Use the Gradle user home directory by default for the download directory for the biome executable.
Previously, the plugin tried to use Maven's home directory, which is not always accessible by a Gradle plugin.
According to the [Gradle docs](https://docs.gradle.org/current/kotlin-dsl/gradle/org.gradle.api.invocation/-gradle/get-gradle-user-home-dir.html),
the user home directory

> is used to cache downloaded resources, compiled build scripts and so on.

From that description, it seems to me to be the proper location for the biome executable.
@nedtwigg
Copy link
Member

Released in plugin-gradle 7.0.0.BETA3 and plugin-maven 2.44.0.BETA3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants