Hello folks, I'm trying to reuse convention plugin...
# gradle
h
Hello folks, I'm trying to reuse convention plugins across multiple android repos and I'm kinda stuck. I imagined bundling all of our convention plugins in a single artifact, publishing them to org's Github Package Registry, and consuming said convention plugins across multiple projects. What I did so far: • created a stand-alone
conventions
project that has one
plugins
sub-project, • in
plugins
`build.gradle.kts`:
Copy code
plugins {
    `java-gradle-plugin`
    `kotlin-dsl`
    `maven-publish`
}

...

gradlePlugin {
    plugins {
        register("application-compose") {
            id = "org.company.example.android.application.compose"
            implementationClass = "AndroidApplicationComposeConventionPlugin"
        }

        register("application") {
            id = "org.company.example.android.application"
            implementationClass = "AndroidApplicationConventionPlugin"
        }

        register("library-compose") {
            id = "org.company.example.android.library.compose"
            implementationClass = "AndroidLibraryComposeConventionPlugin"
        }

        register("library") {
            id = "org.company.example.android.library"
            implementationClass = "AndroidLibraryConventionPlugin"
        }
    }
}

publishing {
    repositories {
        maven {
            name = "GitHubPackages"
            url = uri("<https://maven.pkg.github.com/org/repo>")
            ...
        }
    }
    publications {
        create<MavenPublication>("conventionPlugins") {
            groupId = "org.company.example"
            artifactId = "plugins"
            version = "2024.12.24"
            from(components["java"])
            ...
        }
    }
}
After running
./gradlew publish
I ended up with 5 artifacts, one for each registered plugin and last one being
org.company.example:plugins:2024.12.24
. This is my first time tinkering with plugin publishing so my questions would be: 1. Is my idea even doable? If yes, how do make sure only the bundled plugins artifact is published? 2. How do I go about consuming the plugins? I added internal repository's dependency in the
pluginManagement
block in the settings script of one of the projects I'm trying to migrate to these published plugins, but doing:
Copy code
plugins {
    id("org.company.example.android.library") version "2024.12.24"
    ...
}
in one of the project's modules results in
UnknownPluginException
. Thanking you for your help in advance!
c
After running
./gradlew publish
I ended up with 5 artifacts, one for each registered plugin and last one being
org.company.example:plugins:2024.12.24
.
That's normal. What
kotlin-dsl
does is generate one main artifact that contains the code, and then each registered plugin gets its own artifact that only contains the metadata and a dependency on the main one. If you want to compare, here is one of my plugins,
vite-kotlin
: • The main artifactThe plugin marker artifact You can also see my convention plugins, which generate many plugins out of a single artifact: • Artifact list You should publish all artifacts to ensure everything works normally. After that, you should be able to just declare the repository and have everything work. If you're sure you've done that, send us the Gradle error message