Hamza Kovacevic
12/24/2024, 1:48 PMconventions
project that has one plugins
sub-project,
• in plugins
`build.gradle.kts`:
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:
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!CLOVIS
12/24/2024, 3:50 PMAfter runningThat's normal. WhatI ended up with 5 artifacts, one for each registered plugin and last one being./gradlew publish
.org.company.example:plugins:2024.12.24
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 artifact
• The 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