Skip to content

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

Closed

Description

@kun-zhou

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.

Activity

  1. nedtwigg commented on Feb 11, 2021

    @nedtwigg
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions