Create a Maven Central bundle from Gradle
Use Gradle 9.1+ and Java 17+. This example uses version 0.2.0 of Buildish Maven Bundles for Gradle.
Apply the settings plugin
Add this to settings.gradle.kts:
1pluginManagement {
2 repositories {
3 mavenCentral()
4 gradlePluginPortal()
5 }
6}
7
8plugins {
9 id("org.buildish.atr-maven-bundle.gradle-plugin") version "0.2.0"
10}
11
12rootProject.name = "my-library"
In a Groovy build, add this to settings.gradle:
1pluginManagement {
2 repositories {
3 mavenCentral()
4 gradlePluginPortal()
5 }
6}
7
8plugins {
9 id 'org.buildish.atr-maven-bundle.gradle-plugin' version '0.2.0'
10}
11
12rootProject.name = 'my-library'
If your settings already declare plugin repositories, add mavenCentral() to
that list. Keep the maven-publish plugin and your publication configuration in
each publishing project’s build script.
Create your first ZIP
Use your existing Maven publications or try this small Java library example in
build.gradle.kts:
1plugins {
2 `java-library`
3 `maven-publish`
4}
5
6group = "org.example"
7version = "1.0"
8
9publishing {
10 publications {
11 create<MavenPublication>("main") {
12 from(components["java"])
13 }
14 }
15}
Publications in all projects are included by default. See publication selection if you need exclusions.
Run an unsigned local trial:
1./gradlew -PatrMavenBundle.requireSignatures=false :mavenRepositoryZip
With the example name and version, open
build/maven-bundles/repository/my-library-1.0.zip. It contains the publication
files and checksums in Maven repository layout.
Prepare a signed bundle for Maven Central
For a Java library release, use a namespace you control and configure sources,
Javadoc, and the required POM metadata. For the trial project, add the following
to build.gradle.kts and replace the example project details with your own:
1java {
2 withSourcesJar()
3 withJavadocJar()
4}
5
6publishing.publications.named<MavenPublication>("main") {
7 pom {
8 name.set("My Library")
9 description.set("A description of the library.")
10 url.set("https://github.com/example/my-library")
11 licenses {
12 license {
13 name.set("Apache License, Version 2.0")
14 url.set("https://www.apache.org/licenses/LICENSE-2.0")
15 }
16 }
17 developers {
18 developer {
19 id.set("maintainer")
20 name.set("Library Maintainer")
21 }
22 }
23 scm {
24 connection.set("scm:git:https://github.com/example/my-library.git")
25 developerConnection.set("scm:git:ssh://git@github.com/example/my-library.git")
26 url.set("https://github.com/example/my-library")
27 }
28 }
29}
Choose a signing path:
- If Gradle already signs your publications, run
./gradlew :mavenRepositoryZip. The plugin preserves those signatures and checks that the required files have one. - To generate missing signatures, add
signingto the root build’s existingpluginsblock and configure the signer. Then run./gradlew :prepareMavenBundle --sign-missing :mavenRepositoryZip.
Inspect the resulting ZIP and follow Maven Central’s requirements and bundle upload instructions. For a Njord import, see Export a Njord transportable bundle.