Duplicate repositories from included build

We have a couple of locally developed groovy buildSrc plugins that have external implementation dependencies. We host those dependencies within local maven repositories.

If we use includeBuild for the plugin we currently have to duplicate these external repositories within a pluginManagement block for the projects using our plugins (or not use includeBuild but symlink the plugin directory as buildSrc for the project).

plugin build.gradle:

plugins {
  id ‘example-plugin’
}

dependencies {
  repositories {
    maven {
      url = …
    }
    maven {
      url = …
    }
  }
  implementation ‘com.example:example:1.2.3’
}

consumer project settings.gradle:

pluginManagement {
  repositories {
    maven {
      url = …
    }
    maven {
      url = …
    }
  }
}

includeBuild ‘path/to/example-plugin’

If not duplicated we get an error like so:

FAILURE: Build failed with an exception.

What went wrong:
A problem occurred configuring root project ‘xxx’.

Could not resolve all dependencies for configuration ‘classpath’.
Could not resolve com.example:example:1.2.3.
Required by:
root project : > project :plugins
Could not resolve com.example:example:1.2.3.
Could not get resource 'https://plugins.gradle.org/…
Could not GET 'https://plugins.gradle.org/m2/…
*snip*

It seems like since these are internal implementation dependencies for the plugins we should not have to duplicate the repositories for the projects using the plugins? We are using 8.14.2

Yes, you do have to.
Imagine an included build as standalone project that just happens to run before your build automatically, because that is what indeed happens.
Imagine you published this plugin instead to some repository different from the two where your dependencies live in.

A consumer would then have to provide all three repositories so that your plugin and its dependencies can be resolved, unless you build your plugin as bloody fat jar that repackages its dependencies.

Btw.

symlink the plugin directory as buildSrc for the project

sounds like a horrible idea, especially if you might happen to run multiple builds using it in parallel.
But even without this can have quite unnice side effects.

Yes that makes sense, thank you

regarding the symlink: we thought this would be identical to an includeBuild, does it fool gradle somehow?

I’m not fully sure, and that should make you uneasy. :smiley:

1 Like