This is NOT a step by step tutorial guiding you on how to setup and configure your project to deploy artifacts to Maven Central Repository. There a couple of nice guides with detailed information about all setup requirements related with Maven, Sonatype OSSRH, Nexus Repository, Staging, POM, signing Your Artifact with PGP/GPG, etc.
Once you have enabled your deployment process, this guide aims to distil the core entities involved in that workflow.
First of all let’s clarify the repositories terminology which includes 4 different repositories. Put it simply, they are:
Source Code Repository |
OSSRH Staging --->
OSSRH Releases <--- sync --->
Maven Central Repository
-
The Source Code Repository (e.g. Github) which in Maven POM (Project Object Model) is configured in the environment settings SCM (Software Configuration Management, “also called Source Code/Control Management)”)
-
Staging OSSRH (Open Source Software Repository Hosting) (e.g. Nexus Repository Manager) which in Maven POM is configured under Distribution Management
-
Releases in OSSRH. Successfully closing the Staging repository moves components into the Release repository of OSSRH
-
Maven Central Repository is a repository of software components providing an easy way to access and distribute libraries between developers. Once in Release repository of OSSRH the components will be synced to the Maven Central Repository.
My deployment workflow includes 6 steps. Off course, I could simplify it and automatize some steps. However this is my compromise between control and automation. This means, I do not want to have it completely manual, but I do not want it fully automatic either. So this is the way it gives me some control with less effort and transparency over each step. These steps include:
mvn release:clean
mvn release:prepare
-- Creates release artifacts with corresponding git tag version (e.g.1.1
) and setup next Snapshot version (e.g.1.2-SNAPSHOT
) in POM. Pushmaster
and tag to origin.git push origin <release tag>
-- Pushes the release tag (e.g.1.1
)mvn release:perform
-- Executes the following 2 steps and removes filerelease.properties
.
1. `git checkout` to previous commit corresponding to release (e.g. tag version 1.1).
2. `mvn deploy:deploy` -- push artifacts to Staging OSSRH.
- Search by the Staging repository in Nexus Repository Manager and close it by pressing the Close button, which will trigger the evaluations of the components against the requirements.
- If the Staging Repository was successfully closed in step 5. then release it by pressing the Release button.
git checkout
again to1.2-SNAPSHOT
After these steps the components will move into the release repository of OSSRH where it will be synced to the Central Repository. Note that according to documentation
Upon release, your component will be published to Central: this typically occurs within 10 minutes, though updates to search can take up to two hours.