Nexus & OSSRH
Nexus deployments let you upload packages to a remote Sonatype Nexus repository. Notably, these are commonly used for OSSRH projects to become part of the Maven Central repo.
Sonatype recently devised a new entry point for Maven Central called the Central Portal. If you are a new publisher or an old publisher who decided to migrate to Central Portal, please check the docs.
Add a new spec with nexusSpec {}
. It adds a mandatory property called repositoryUrl
, which is the remote URL
of the sonatype repo. This defaults to https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/
, one of the
OSSRH urls that can be synced to Maven Central.
kotlindeployer {
// Common configuration...
project.description.set("Handy tool to publish maven packages in different repositories.")
nexusSpec {
// Target URL. You can use `ossrh`, `ossrh1`, `ossrhSnapshots`, `ossrhSnapshots1` or your own URL
repositoryUrl.set(ossrh1)
// For OSSRH projects, these are the credentials that were used to register the package group into OSSRH
auth.user.set(secret("SONATYPE_USER"))
auth.password.set(secret("SONATYPE_PASSWORD"))
// Note: signing is required for Maven Central sync
signing.key.set(secret("SIGNING_KEY"))
signing.password.set(secret("SIGNING_PASSWORD"))
}
// If needed, you can add other named specs.
nexusSpec("snapshot") {
repositoryUrl.set(ossrhSnapshots1)
release.version.set("latest-SNAPSHOT")
...
}
}
Maven Central sync
Sonatype's OSSRH projects are allowed to sync artifacts with the Maven Central repository. The process is generally tricky, because you have to:
- Build maven packages with a very strict set of rules (for example, signing is mandatory)
- Deploy them to
oss.sonatype.org/service/local/staging/deploy/maven2
ors01.oss.sonatype.org/service/local/staging/deploy/maven2
- Access the web interface at
oss.sonatype.org
ors01.oss.sonatype.org
- Login with your credentials
- Find the staging repository corresponding to the upload,
Close
it and thenRelease
it
Deployer streamlines the process so that only the first step is really your responsibility.
First, enable maven central sync using syncToMavenCentral
:
kotlinnexusSpec {
syncToMavenCentral = true
auth.user = secret("SONATYPE_USER")
auth.password = secret("SONATYPE_PASSWORD")
}
Then simply run the deploy task. Deployer will:
- Validate your artifacts and POM file, to ensure they won't be rejected by the backend
- Fail with clear errors if any issue is found
- Use Sonatype's REST APIs to create a staging repository in your Sonatype account
- Upload the artifacts
- Use Sonatype's REST APIs to close and release the staging repository