When publishing a Gradle plugin, you must publish both the plugin jar and the plugin marker artifact. The marker artifact is required for users to apply your plugin using the plugins {} DSL.
Required plugins:
java-gradle-pluginmaven-publishsigning
Key Configuration Requirements:
- Javadoc and Sources: OSS libraries on Maven Central must include these. Use
java.withJavadocJar() and java.withSourcesJar(). - Plugin Marker: Use
afterEvaluate to configure the automatically created ...PluginMarkerMaven publication. - POM Metadata: Ensure you provide name, description, URL, licenses, developers, and SCM information.
- Signing: You must sign both the
plugin publication and the pluginMarker publication.
plugins {
`java-gradle-plugin`
`maven-publish`
signing
}
java {
withJavadocJar()
withSourcesJar()
}
publishing {
publications {
afterEvaluate {
named<MavenPublication>("myPluginPluginMarkerMaven") {
pom {
// ... metadata ...
}
}
}
create<MavenPublication>("plugin") {
from(components["java"])
// ... version mapping and pom ...
}
}
repositories {
// Configure Sonatype repositories based on version (SNAPSHOT vs Release)
}
}
afterEvaluate {
signing {
sign(publishing.publications["plugin"], publishing.publications["myPluginPluginMarkerMaven"])
}
}