Open Source

Other versions of this page

Improve this page on GitHub

Sonatype & Maven Central

Add a new spec with sonatypeSpec {} or nexusSpec {}. It adds a mandatory property called repositoryUrl, which is the remote URL of the sonatype repo. This defaults to, one of the OSSRH urls that can be synced to Maven Central.

kotlin logokotlin
deployer { // Common configuration... project.description.set("Handy tool to publish maven packages in different repositories.") sonatypeSpec { // 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. sonatypeSpec("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 or
  • Access the web interface at or
  • Login with your credentials
  • Find the staging repository corresponding to the upload, Close it and then Release it

Deployer streamlines the process so that only the first step is really your responsibility. First, enable maven central sync using syncToMavenCentral:

kotlin logokotlin
sonatypeSpec { 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