You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Gradle Plugin incompatible with mutli-project build and convention plugins #747
Gradle 6.7.1 reccommends convention plugins for sharing build logic across multi-project repositories.
In the official Gradle documentation, the root project often has no build.gradle - only a settings.gradle that includes other projects. Build logic is shared not through allprojects, but through convention plugins under buildSrc.
Currently, the Gradle Spotless plugin assumes it is running from the root project, which makes it incompatible with the guidance in the official Gradle documentation.
Gradle version
6.7.1
Spotless version
Plugin version 5.8.2
Operating system
Latest OSX
Spotless configuration block
In the following repository structure, with one subproject, a root settings file, and one convention plugin:
% ./gradlew build
> Task :spotlessInternalRegisterDependencies FAILED
FAILURE: Build failed with an exception.
* What went wrong:
A problem was found with the configuration of task ':spotlessInternalRegisterDependencies' (type 'RegisterDependenciesTask').
> Cannot write to file '.../some-project/build/tmp/spotless-register-dependencies' specified for property 'unitOutput', as ancestor '.../some-project/build' is not a directory.
Aha! Thanks, this is helpful diagnostic info. I this this might be a dupe of #741, but with a new cause which makes the bug easier to understand.
The root project has special privileges when it comes to registering dynamic dependencies, so we have to use it for the "registerDepencies" task. I think we can fix it by ensuring that the build directory exists for the root project...
I tried to reproduce the issue (PR linked above), and I can only reproduce if I create a file (not a folder, but a file), in the build spot, which would be a bug outside of Spotless.
Hi Ned,
I am using com.diffplug.spotless:spotless-plugin-gradle:5.9.0
I still see a problem when used in Gradle mutli-module-project build environment (with convention plugins).
'spotlessInternalRegisterDependencies' task fails reporting it cannot see an artifact in provided repositories.
You probably need to add a repository containing the '[org.scalameta:scalafmt-core_2.11:2.0.1]' artifact in the 'build.gradle' of your root project. E.g.: 'buildscript { repositories { mavenCentral() }}' org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration$ArtifactResolveException: Could not resolve all files for configuration ':detachedConfiguration1'. at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration.rethrowFailure(DefaultConfiguration.java:1406) at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration.access$3600(DefaultConfiguration.java:149) at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration$DefaultResolutionHost.rethrowFailure(DefaultConfiguration.java:2011) at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration$ConfigurationFileCollection.visitContents(DefaultConfiguration.java:1379) at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration.visitContents(DefaultConfiguration.java:497) at org.gradle.api.internal.file.AbstractFileCollection.getFiles(AbstractFileCollection.java:126) at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration_Decorated.getFiles(Unknown Source) at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration.resolve(DefaultConfiguration.java:487) at com.diffplug.gradle.spotless.GradleProvisioner.lambda$fromRootBuildscript$1(GradleProvisioner.java:74) at com.diffplug.gradle.spotless.GradleProvisioner$RootProvisioner.provisionWithTransitives(GradleProvisioner.java:56) at com.diffplug.spotless.JarState.provisionWithTransitives(JarState.java:68) at com.diffplug.spotless.JarState.from(JarState.java:57)
I have added mevenCentral() as suggested in the error message but of no help.
Since there is no build.gradle file at the project root how is that spotless reading any repository declaration in a multi-project environment?
Since there is no build.gradle file at the project root
Can you put one there? If not, why not? From the error message: need to add a repository containing the '[org.scalameta:scalafmt-core_2.11:2.0.1]' artifact in the 'build.gradle' of your root project.
The reason for this is that Gradle has different rules for resolving dependencies in the root project than in child projects.
As stated earlier, Gradle has different rules for the root project than for child projects. Spotless cannot work unless you add the repositories block to the root project, and the error message is clear about that.
If you want to do the buildscript { repositories {, etc with a buildSrc module, I think you can do that. But you'll have to apply that plugin to the root project, there is no way around that. e.g. apply: 'my-buildsrc-spotless-root-project'. There might be a way to accomplish this with the settings.gradle file, but I don't know what the magic phrase would be.
Bad idea warning: You might be able to update the root project from a child project. You could do apply: 'my-buildsrc-plugin' in a subproject, and grab the root project and update its buildscript. That is bad practice and might not work, and you'd need to add some kind of flag to make sure that you only modify it once. If Gradle ever ships parallel project configuration (they already have parallel execution, but not yet configuration), then this will definitely not work.
Activity
nedtwigg commentedon Dec 10, 2020
Aha! Thanks, this is helpful diagnostic info. I this this might be a dupe of #741, but with a new cause which makes the bug easier to understand.
The root project has special privileges when it comes to registering dynamic dependencies, so we have to use it for the "registerDepencies" task. I think we can fix it by ensuring that the
builddirectory exists for the root project...PR's wanted!
nedtwigg commentedon Jan 4, 2021
Earlier I said:
but it turns out we were already doing that
spotless/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/RegisterDependenciesTask.java
Line 105 in be2150c
I tried to reproduce the issue (PR linked above), and I can only reproduce if I create a file (not a folder, but a file), in the
buildspot, which would be a bug outside of Spotless.upendrao commentedon Feb 2, 2021
Hi Ned,
I am using com.diffplug.spotless:spotless-plugin-gradle:5.9.0
I still see a problem when used in Gradle mutli-module-project build environment (with convention plugins).
'spotlessInternalRegisterDependencies' task fails reporting it cannot see an artifact in provided repositories.
You probably need to add a repository containing the '[org.scalameta:scalafmt-core_2.11:2.0.1]' artifact in the 'build.gradle' of your root project. E.g.: 'buildscript { repositories { mavenCentral() }}' org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration$ArtifactResolveException: Could not resolve all files for configuration ':detachedConfiguration1'. at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration.rethrowFailure(DefaultConfiguration.java:1406) at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration.access$3600(DefaultConfiguration.java:149) at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration$DefaultResolutionHost.rethrowFailure(DefaultConfiguration.java:2011) at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration$ConfigurationFileCollection.visitContents(DefaultConfiguration.java:1379) at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration.visitContents(DefaultConfiguration.java:497) at org.gradle.api.internal.file.AbstractFileCollection.getFiles(AbstractFileCollection.java:126) at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration_Decorated.getFiles(Unknown Source) at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration.resolve(DefaultConfiguration.java:487) at com.diffplug.gradle.spotless.GradleProvisioner.lambda$fromRootBuildscript$1(GradleProvisioner.java:74) at com.diffplug.gradle.spotless.GradleProvisioner$RootProvisioner.provisionWithTransitives(GradleProvisioner.java:56) at com.diffplug.spotless.JarState.provisionWithTransitives(JarState.java:68) at com.diffplug.spotless.JarState.from(JarState.java:57)I have added mevenCentral() as suggested in the error message but of no help.
Since there is no build.gradle file at the project root how is that spotless reading any repository declaration in a multi-project environment?
nedtwigg commentedon Feb 2, 2021
Can you put one there? If not, why not? From the error message: need to add a repository containing the '[org.scalameta:scalafmt-core_2.11:2.0.1]' artifact in the 'build.gradle' of your root project.
The reason for this is that Gradle has different rules for resolving dependencies in the root project than in child projects.
upendrao commentedon Feb 2, 2021
Ned, Appreciated your quick reply :-)
Yes. Then it works.
Since(Gradle 6.7+) all the build logic has been moved to buildSrc module there is no need for one except in this occasion.
nedtwigg commentedon Feb 2, 2021
As stated earlier, Gradle has different rules for the root project than for child projects. Spotless cannot work unless you add the repositories block to the root project, and the error message is clear about that.
If you want to do the
buildscript { repositories {, etc with abuildSrcmodule, I think you can do that. But you'll have to apply that plugin to the root project, there is no way around that. e.g.apply: 'my-buildsrc-spotless-root-project'. There might be a way to accomplish this with thesettings.gradlefile, but I don't know what the magic phrase would be.Bad idea warning: You might be able to update the root project from a child project. You could do
apply: 'my-buildsrc-plugin'in a subproject, and grab the root project and update its buildscript. That is bad practice and might not work, and you'd need to add some kind of flag to make sure that you only modify it once. If Gradle ever ships parallel project configuration (they already have parallel execution, but not yet configuration), then this will definitely not work.Fix CI breakage from this dependency bump
Fix Spotless 8.x cross-project classloader failure