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
Applying the gradle plugin directly in the subproject does not work #795
I am trying to add the Gradle plugin to a subproject directly like so
plugins {
id 'application'
id "com.diffplug.spotless" version "5.10.0"
}
without a build.gradle for the root project. But ./gradlew b fails due to
* What went wrong:
Execution failed for task ':spotlessInternalRegisterDependencies'.
> Could not resolve all files for configuration ':detachedConfiguration2'.
> Cannot resolve external dependency com.google.googlejavaformat:google-java-format:1.7 because no repositories are defined.
Required by:
project :
However, if I add the plugin to the root project first or add a repository in the buildscript in the root build.gradle, the issue is resolved. I am curious why this is the case. I understand spotless use the buildscript of the root project but it eludes why including the plugin in the root project without defining the build script works.
The simple reason is that Gradle allows you to declare dynamic buildscript dependencies in the root project and nowhere else.
The first thing is to distinguish between buildscript dependencies and project dependencies. You can dynamically declare repos and dependencies, but those are all project repositories and dependencies. For the buildscript, those repositories and dependencies can only be declared at the root, with the exception that you can add a new dependency in a subproject with a plugins block.
If you are especially security conscious, then the security rules for your buildscript repositories might be more locked-down than the rules for your project repositories. Trusting trust and all that. Not all plugins follow this rule, but plugins really should download all their dependencies from buildscript repositories, and not from project repositories.
If you're curious to dig in, the exact code is here:
Activity
nedtwigg commentedon Feb 11, 2021
The simple reason is that Gradle allows you to declare dynamic buildscript dependencies in the root project and nowhere else.
The first thing is to distinguish between buildscript dependencies and project dependencies. You can dynamically declare repos and dependencies, but those are all project repositories and dependencies. For the buildscript, those repositories and dependencies can only be declared at the root, with the exception that you can add a new dependency in a subproject with a
pluginsblock.If you are especially security conscious, then the security rules for your buildscript repositories might be more locked-down than the rules for your project repositories. Trusting trust and all that. Not all plugins follow this rule, but plugins really should download all their dependencies from buildscript repositories, and not from project repositories.
If you're curious to dig in, the exact code is here:
GradleProvisioner.javaRegisterDependenciesTask.javaThe PR which implemented this approach is #503, and a similar topic is discussed in #747.