This is the documentation about how to deploy to maven central repository (central.sonatype.com)
not the `OSSRH (oss.sonatype.org)
Prepare the account
You need to create one account and register a namespace.
Prepare GPG key
Create one new GPG key
Create a new gpg key. You can get from github’s documentation. If you want to re-use the existing gpg key. You can ignore this step.
gpg --list-secret-keys --keyid-format=short
You will get the some output like the following picture. The AE0CF2F3
is the key id.
Distributing the GPG key
Maven central repository now supports the following gpg keyservers:
keyserver.ubuntu.com
keys.openpgp.org
pgp.mit.edu
You can rungpg --keyserver keyserver.ubuntu.com --send-keys AE0CF2F3
to export the GPG key. If you cannot run this command successfully, you still can not go to the websitehttps://keyserver.ubuntu.com/#submitKey
to submit the public key (rungpg --armor --export AE0CF2F3
to generate it).
Sign (Gradle)
Solution 1
Run gpg --export-secret-keys -o ~/.gnupg/secring.gpg
to export all secret keys to ~/.gnupg/secring.gpg
.
Add the following content to ~/.gradle/gradle.propertie
(user’s home gradle properties, not the project’s gradle properties.)
signing.keyId=AE0CF2F3 #must use short one
signing.password=[the passphrase of the gpg key]
signing.secretKeyRingFile=/Users/ivyxjc/.gnupg/secring.gpg
You can run gradle sign
to verify whether it works or not.
Solution 2
Publish to maven central (Gradle)
I choose the gradle maven publish plugin.
Here is one example configuratiion
plugins {
id("com.vanniktech.maven.publish") version "0.31.0-rc2"
}
mavenPublishing {
pom {
name.set("*****")
description.set("A description of what my library does.")
inceptionYear.set("2020")
url.set("https://github.com/username/library/")
licenses {
license {
name.set("The Apache License, Version 2.0")
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
distribution.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
}
}
developers {
developer {
id.set("username")
name.set("User Name")
url.set("https://github.com/username/")
}
}
scm {
url.set("https://github.com/username/library/")
connection.set("scm:git:git://github.com/username/library.git")
developerConnection.set("scm:git:ssh://[email protected]/username/library.git")
}
}
}
Then you can run ORG_GRADLE_PROJECT_mavenCentralUsername={maven_central_username} ORG_GRADLE_PROJECT_mavenCentralPassword={maven_central_password} ./gradlew publishAllPublicationsToMavenCentralRepository
publish to the maven central. You can see the deployments in this page Sonatype deployments. You can also publish in this page.
The mave_central_username
and the maven_central_password
is not the username and password of your sonatype account. It’s generated in your accout page Sonatype Account.
Notes
SNAPSHOT version
You need to enable SNAPSHOTS
in sonatype account page first
maven central repository’s Central Portal Namespaces
The documentation of this gradle plugins declare that it support upload the snapshot version. But I still meet the 401 issue which should be fixed. Fix 401 error when publishing snapshots to Central Portal