Skip to main content

Gradle

Publish a Java publication from Gradle to Maven Central with a generated POM and a prepared, signed Central ZIP. Select the Gradle project directory or its build.gradle or build.gradle.kts file. Use --ecosystem gradle when the directory also contains another ecosystem's manifest.

Prepare one publication​

Configure a named MavenPublication with Central's required POM metadata and sign it with Gradle's signing plugin. For a Java library, include its sources and Javadoc JARs. Publish that one publication to a fresh staging repository on disk with a file: URL. For example, Gradle's task for publication mavenJava and repository centralStaging is publishMavenJavaPublicationToCentralStagingRepository. Gradle writes its generated POM to build/publications/mavenJava/pom-default.xml by default. Gradle Maven Publish guide, Sonatype's Gradle guide

Create a new ZIP32 archive of up to 256 MiB. Keep the Maven repository layout and include only the selected version directory. For example, if the staging repository lives at build/central-staging, run this from the Gradle project directory.

(cd build/central-staging && zip -r ../central-bundle.zip org/example/demo/1.2.3)

The ZIP must contain the exact bytes of the generated POM selected by publicationPomPath and its artifacts with .asc, .md5, and .sha1 companions. For jar packaging, include the main, sources, and Javadoc JARs. For pom packaging, a platform or BOM can publish without JARs. Classified ZIP and TAR.GZ attachments are supported. Keep repository-level maven-metadata.xml and other publications outside the ZIP. Releaser checks the archive bytes against the supplied digests and parses the detached OpenPGP signatures. Central verifies the cryptographic signatures during deployment. Central bundle layout, Central requirements

Include Gradle Module Metadata​

If the generated POM advertises Gradle Module Metadata, include the matching artifactId-version.module file with its signature and checksums. Releaser checks metadata 1.1 up to 1 MiB. The metadata's component coordinates must match the POM. Variant file names and URLs use ASCII letters, digits, underscores, dots, and dashes. Each URL must name an artifact in the selected version directory, and the recorded size and four native digests must match its bytes. Releaser accepts optional SHA-256 and SHA-512 sidecars and checksums of .asc signatures. Gradle Module Metadata guide, Gradle metadata writer

The ZIP covers one self-contained publication. Gradle's format also allows available-at variants, a component url, and file references outside the version directory. Those forms require a wider repository layout than this adapter accepts. The adapter also requires jar or pom packaging, which excludes Android AAR publications. Gradle Module Metadata specification

Configure and publish​

Set both paths relative to the selected Gradle project. Set publicationPomPath to one generated XML POM, including when the build has several publications. Keep the settings literal. Set the variable named by authEnv to the Portal token pair in username:password form.

ecosystems:
gradle:
enabled: true
publicationPomPath: build/publications/mavenJava/pom-default.xml
centralBundlePath: build/central-bundle.zip
registries:
- name: central
url: https://central.sonatype.com
authEnv: YOUR_CENTRAL_TOKEN_VARIABLE
release validate path/to/project --ecosystem gradle
release publish path/to/project --ecosystem gradle --registry central --dry-run
release publish path/to/project --ecosystem gradle --registry central

Validation and dry runs read the generated POM and ZIP locally. The build script is a project marker. Releaser sends the checked ZIP bytes to the selected Portal unchanged and reports the deployment state and ID. With publish.dryRunFirst, the preview and upload use the same checked ZIP. For a version change, update the Gradle project and regenerate both files. Central deployment states