Automating publishing to maven central via Sonatype
After releasing several open-source projects which are not using maven for the build framework (they use gradle), I was faced with the harsh reality that if you don't use maven, it is pretty hard to automate the process. The current version of gradle allows you to upload to a maven compatible repo, but to upload to maven central there are some constraints (like pgp signing) that gradle does not (currently) support.
In order to publish your artifacts to maven central via Sonatype (unclear if there is another way to be honest), you need to follow the instructions on how to set it up (you need to create a Jira Ticket). You also need to have a pgp key and if you don't, you can follow these instructions.
Using gradle, you can simply create a maven compatible layout of your artifacts:
Note that a big part of the previous code is setting up the right information in the pom file to comply with the set of requirements. Also note that you do not need to use gradle at all as long as you generate a maven compatible layout (with pom files).
You can then use the script I have 'gisted' on github: maven_staging_upload.groovy. The script simply takes the pom files you want to upload as an input and will prompt you for your pgp passphrase only once! Make sure you follow the initial setup:
You then need to login to Nexus to verify that the upload worked properly. You can then close the staging repository and release it. It will make its way to maven central shortly. The very first time, you need to activate central sync!
I guess it is not fully automated as you still need to manually close/release the staging repository but the painful part (the part about uploading the artifacts to staging) is fully automated thanks to gradle and the script.
You can use the gradle plugins that I open sourced to help with the release: the
org.linkedin.repository
and org.linkedin.release
plugin can simplify your build code (for example the plugin takes care of the javadoc and sources requirements).
Note that this script can be used totally independently of gradle and you do not need to use gradle to use it!
Thanks to Jakub Holy for this blog post which helped me in understanding the steps I needed to follow in order to automate them.
I am also hopeful that the 1.0 release of gradle will render my script obsolete!
Nov 27 2010 - Posted by Yan in