This Gradle
plugin simplifies the process of publishing your artifacts to the
Sonatype Maven Central Repository. It utilizes standard plugins
such as the Maven Publish Plugin
and the Signing Plugin.
pluginManagement {
repositories {
gradlePluginPortal()
mavenCentral()
}
}
plugins {
id("dev.g000sha256.sonatype-maven-central") version "1.0.0"
}
Note
The plugins org.gradle.maven-publish
and org.gradle.signing
will be applied automatically,
so you don't need to add them manually.
The plugin can have two types of publishing:
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 toMaven Central
By default, the type is set as 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 username>
SonatypeMavenCentral.Password=<your sonatype password>
You also can override the credentials using a plugin extension:
sonatypeMavenCentralRepository {
credentials {
username = "<your sonatype username>"
password = "<your sonatype password>"
}
}
publishing {
publications {
register<MavenPublication>("<your publication variant>") {
groupId = "<your publication group id>"
artifactId = "<your publication artifact id>"
version = "<your publication version>"
// pom/component/artifacts configuration
}
}
}
Store your GPG credentials
securely in your private Gradle
properties file (~/.gradle/gradle.properties
):
signing.keyId=<your signing keyId>
signing.password=<your signing password>
signing.secretKeyRingFile=<your path to secring.gpg file>
Sign the publication:
signing {
val publication = publishing.publications["<your publication variant>"]
sign(publication)
}
./gradlew publish
./gradlew publishAllPublicationsToSonatypeMavenCentralRepository
./gradlew publish<your publication variant>PublicationToSonatypeMavenCentralRepository