What is the cleanest way to publish convention plu...
# community-support
l
What is the cleanest way to publish convention plugins to maven, so that a build (in another git repo) can use them via a shared maven repository?
I have a multi-project build that uses buildSrc with a layout like the one described here:
Copy code
├── buildSrc
│   ├── build.gradle.kts
│   ├── settings.gradle.kts
│   ├── src
│   │   ├── main
│   │   │   └── kotlin
│   │   │       ├── myproject.java-conventions.gradle.kts
│   │   │       └── myproject.library-conventions.gradle.kts
I have another build in a separate repo where I also need to use one of these convention plugins, let's say
myproject.java-conventions
. I've found that I can publish all of buildSrc as a single artifact by applying maven-publish in
buildSrc/build.gradle.kts
, and then in the consuming build doing this:
Copy code
// settings.gradle.kts
pluginManagement {
    resolutionStrategy {
        eachPlugin {
            if (requested.id.namespace == "myproject") {
                val version = checkNotNull(requested.version) { "No version specified for plugin $requested"}
                useModule("com.mygroup:buildSrc:$version")
            }
        }
    }
}

# version catalog
[plugins]
myproject-java-conventions = { id = "myproject.java-convention", version.ref = "myproject" }

// build.gradle.kts
plugins {
    alias(libs.plugins.myproject.java.conventions)
}
Is this the cleanest/simplest way to do this? Or is there some way to remove the need for the custom
resolutionStrategy
without adding equal or greater complexity elsewhere?
v
If you also publish the plugin marker artifacts you should not need a resolution strategy.
l
Thank you! I didn't realize that
:buildSrc:publishPluginMavenPublicationToMyRepository
would omit the plugin marker artifacts. I switched to
:buildSrc:publishAllPublicationsToMyRepository
.
👌 1