Migrating from buildSrc to build-logic for convention plugins with multiple repositories

I’m currently migrating my convention plugins from buildSrc to build-logic as shown in the skeleton from gradle init.

My convention plugins need a second repository, so my build-logic/build.gradle looks like:

repositories {
    gradlePluginPortal()
    maven { url("https://maven.hello2morrow.com/repository") }
}

Unfortunateley, this doesn’t work anymore. In the included build, only the Gradle Plugin Portal repository is used:

A problem occurred configuring root project 'truststorebuilder-gradle-plugin'.
> Could not resolve all files for configuration ':classpath'.
   > Could not find com.hello2morrow:sonargraph-gradle-plugin:8.8.0.
     Searched in the following locations:
       - https://plugins.gradle.org/m2/com/hello2morrow/sonargraph-gradle-plugin/8.8.0/sonargraph-gradle-plugin-8.8.0.pom
     If the artifact you are trying to retrieve can be found in the repository but without metadata in 'Maven POM' format, you need to adjust the 'metadataSources { ... }' of the repository declaration.
     Required by:
         project : > project :build-logic

Am I missing something?

Newer versions of this dependent plugin are hosted on the Plugin Portal, so I can get rid of the additional repository. But the question remains: Why isn’t the second repository searched in the included build?

Repositories are per build.
And included build is a potentially stand-alone build.
It is “just” triggered automatically and its result used.
Whether it is building a normal dependency or plugin doesn’t matter.
Repositories are never leaking into the consumer, neither when publishing something, nor when using an included build.
It is always the consumer build, that controls the repositories.
Corporate rules for example often demand that only internal audited mirrors are used and no other repositories from the wild.

So in your case, the consuming build would be the main build and you would need to add this repository to the plugin repositories for the dependency of the plugin to be resolved.

Thanks for the input and the background. I can confirm that the following settings.gradle works for my build-logic included build:

pluginManagement {
    includeBuild('build-logic')
    repositories {
        gradlePluginPortal()
        maven { url("https://maven.hello2morrow.com/repository") }
    }
}

So, the code block

repositories {
    gradlePluginPortal()
}

originally generated by gradle init and placed in build-logic/gradle.build, is only be used when building build-logic as a standalone project and is not considered during the normal build process?

No, you need both.
The included build builds the same, whether you run it standalone or included.
And the including build also runs the same, whether you include that build or use pre-built artifacts.
So you need the custom repository in both places.
In the included build for building it and in the consuming build for consuming it.

1 Like