Publish to Maven Central
In this tutorial, we will go through the process of publishing to Maven Central.
The sample project is here.
We need the following before we can publish components to Maven Central.
- JIRA account for Sonatype OSSRH (OSS Repository Hosting)
- Claim your namespace on Maven Central repository
Refer to official documentation of OSSRH to set up the above.
If your project is hosted at GitHub, and use io.github.[user]
or com.github.[user]
as group name, then you don't need to claim your namespace.
Again they are one-off things, If you have done that you may go ahead.
#
Project setup#
gradle.propertiesAdd the OSSRH account information to gradle.properties
.
# ...repository.mavencentral.username=your-usernamerepository.mavencentral.password=your-passwordrepository.mavencentral.newUser=false# ...
Note the newUser
line. Maven Central use different servers to publish and manage publication depends on whether the account is a 'new' account. If the account is registered before Feb 2021, it is an 'old' account.
Jarbird adjusts the URL to publish components according to the newUser
flag. Default is true
.
#
build.gradleTell Jarbird plugin that we want to publish to Maven Central.
- build.gradle
- build.gradle.kts
// ...jarbird { pub { mavenCentral() }}// ...
// ...jarbird { pub { mavenCentral() }}// ...
#
pom.yamlIt is required to provide sufficient information about the component before it is approved to be published. This information includes:
- The proper GAV coordinate.
- Description
- URL that hosts the source code
- Developer's information.
Refer to Sonatype page for detailed requirements of POM to publish component to Maven Central.
Jarbird get all of those at the pom.yaml
file:
group: jarbirdsamplesartifactId: mevendemoversion: 1.0packaging: jar
licenses: - name: Apache-2.0 dist: repo
developers: - id: demo name: Jarbird Demo email: jarbird.demo@fake-email.com
scm: repoType: github.com repoName: demo/jarbird-samples/maven-demo
See reference for more details about the content of pom.yaml
.
Jarbird plugin read the file and create a proper POM file for publishing automatically.
With this setup, we can see more tasks available with ./gradlew tasks
Jarbird publishing tasks------------------------jbPublish - PublishjbPublishMavencentraldemo - Publish module 'mavencentraldemo' to all targeted repositoriesjbPublishMavencentraldemoToMavenCentral - Publish module 'mavencentraldemo' to Maven CentraljbPublishMavencentraldemoToMavenLocal - Publish module 'mavencentraldemo' to Maven Local repositoryjbPublishMavencentraldemoToMavenRepositories - Publish module 'mavencentraldemo' to all Maven repositoriesjbPublishToMavenCentral - Publish to Maven CentraljbPublishToMavenLocal - Publish to Maven Local repositoryjbPublishToMavenRepositories - Publish to all Maven repositories
The task jbPublish
publishes component to all specified repositories, which is MavenLocal and MavenCentral for this sample. We may use jbPublishToMavenCentral
to publish our component to the Maven Central repository only.
After published the component to Maven Central successfully, we need to release the component manually at the OSSRH website.