[OSD600] Releasing a project on Maven Central
This week, I published my jssg-project to Maven Central and I would like to journal my process so that it will help others (as well as me) save time on the future publishment.
Preconditions
- Type
mvn compile
andmvn test
to make sure the project is built successfully and there are no unit test failures
Create a repository for the project in the Maven Central Repository
Notes:
- The only allowed
groupId
for Github projects areio.github.*
for example:io.github.trangntt-016
- Make sure that the
groupId
in your project matches with thegroupId
in your ticket. ThegroupId
is like the address of your project, it has nothing to do with the project structure. - To verify that you are the owner of your GH, you’ll be asked to create a temporary, public repository with a format like
https://github.com/trangntt-016/OSSRH-75407
in whichOSSRH-75407
is your ticket number - Once your ticket is raised, you can wait as someone needs to be assigned to it and take action. If it’s weekend or on holiday, chances are it will take more time for your repository to get approved (tickets is tagged as
resolved
). And you can only release your project after your
Setting up file signing through GnuPG
Follow the instruction to setup GnuPG from here
However, the Url’s keyserver in the instruction is deprecated. You should use keyserver.ubuntu.com
and the command line to send your public key to the server is like:
gpg --keyserver hkp://keyserver.ubuntu.com:80 --send-keys BA924657A09D7D13E80A5B19839A6A1B6C672CE9
To verify whether it was been sent without errors, execute the following command to receive the key:
gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys BA924657A09D7D13E80A5B19839A6A1B6C672CE9
Setting up pom.xml
and settings.xml
Follow the instruction to set up pom.xml
and deployment from here
Note: As of February 2021, all new projects began being provisioned on https://s01.oss.sonatype.org/ so you cannot use https://oss.sonatype.org
Deployment and Release
mvn clean deploy
The successful execution of this command will show the snapshot of your project here
Then we need to release the project using the command:
mvn clean deploy -P release
Notes:
- When
mvn clean deploy
if you have401
error though your credentials are correct, check the path ofsettings.xml
and make sure it’s under~/.m2/
and not~/.m2/repository
- Make sure the version in your project is set with
SNAPSHOT
1.0.0-SNAPSHOT because you’re still under active development. - When uploading your codes to GH and if your project has
CI/CD
which does somebuild
, add-Dpgp.skip
to skip asking for PGP’s keys.
Testing
I asked my friend to test my library and it works as I expected.
Happy coding