This is an unofficial Gradle plugin that simplifies the process of publishing your artifacts to the Sonatype Maven Central Repository. It uses the standard Maven Publish plugin and Signing plugin, and auto-applies the Gradle Signing plugin for in-memory PGP keys.
pluginManagement {
repositories {
mavenCentral()
}
}plugins {
id("dev.g000sha256.sonatype-maven-central") version "<latest>"
}Note
The plugins org.gradle.maven-publish, org.gradle.signing, and
dev.g000sha256.signing will be applied automatically, so you don't need to
add them manually.
The plugin supports two publishing types:
SonatypeMavenCentralType.Manual(default) - a deployment will go through validation and require the user to manually publish it via the Portal UISonatypeMavenCentralType.Automatic- a deployment will go through validation and, if it passes, will be automatically published to Maven Central
By default, the type is set to Manual, but you can override it using a plugin extension:
import g000sha256.sonatype_maven_central.SonatypeMavenCentralType
sonatypeMavenCentralRepository {
type = SonatypeMavenCentralType.Automatic
}Store your Sonatype credentials
securely in your private Gradle properties file (~/.gradle/gradle.properties):
SonatypeMavenCentral.Username=<your sonatype portal username>
SonatypeMavenCentral.Password=<your sonatype portal password>For CI/CD, the plugin also reads the credentials from environment variables:
SONATYPE_USERNAME=<your sonatype portal username>
SONATYPE_PASSWORD=<your sonatype portal password>You can also override the credentials using a plugin extension:
sonatypeMavenCentralRepository {
credentials {
username = "<your sonatype portal username>"
password = "<your sonatype portal password>"
}
}Note
The plugin reads credentials in the following order: extension, then environment variable, then Gradle property.
publishing {
publications {
register<MavenPublication>("<your publication variant>") {
// your publication configuration
}
}
}There are two steps: add signing keys and choose what to sign.
The plugin auto-applies the Gradle Signing plugin for in-memory PGP keys.
For CI/CD, set environment variables:
SIGNING_KEY=<your signing key>
SIGNING_PASSWORD=<your signing password>
# optional
SIGNING_KEY_ID=<your signing key id>Or store the credentials in your private Gradle properties file (~/.gradle/gradle.properties):
signing.key=<your signing key>
signing.password=<your signing password>
# optional
signing.keyId=<your signing key id>Note
If those values aren't resolved, the standard Signing plugin's
file-based GPG credentials
(signing.keyId, signing.password, signing.secretKeyRingFile) still work.
You can also override the configured keys via your own signing block:
signing {
useInMemoryPgpKeys("<your signing key>", "<your signing password>")
}A specific publication:
signing {
val publication = publishing.publications["<your publication variant>"]
sign(publication)
}or all publications:
signing {
sign(publishing.publications)
}See signing publications in the Gradle docs for more options.
./gradlew publishor
./gradlew publishAllPublicationsToSonatypeMavenCentralRepositoryor
./gradlew publish<your publication variant>PublicationToSonatypeMavenCentralRepository