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

Applying the gradle plugin directly in the subproject does not work #795

Closed
kun-zhou opened this issue Feb 11, 2021 · 1 comment
Closed
Labels

Comments

@kun-zhou
Copy link

kun-zhou commented Feb 11, 2021

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.

@nedtwigg
Copy link
Member

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:

The PR which implemented this approach is #503, and a similar topic is discussed in #747.

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

No branches or pull requests

2 participants