Previously I wrote an article about hosting an artifact on GitHub. This time I will show you how to host it on Maven Central so people can easily grab it without adding any repository tag to their pom.
Steps
There are a few things to adhere in order for your artifact to be hosted.
- Create a SonaType JIRA Ticket
- Your pom.xml needs to meet a minimum requirement
- You must supply the source code and javadoc
- You must sign your artifact with GPG/PGP
Lets look into these three steps in detail
Create a SonaType JIRA Ticket
Before you can get your artifact into Maven Central, It is needed to deploy it to Nexus repository for it to be synced into the Maven Central repository. Before that, you need to generate a ticket to register your groupId. Sign up here to generate a ticket. This may take up to two days.
POM
Your pom file needs to have sufficient metadata. You must specify these elements in your pom file.
- Correct Coordinates
NAME TAG groupId org.jpedal
artifactId FooBar
Version 1.0
- Correct Coordinates
- Project Name, Description and URL
NAME TAG name org.jpedal:FooBar
description Description or your product
url Your company URL
- Project Name, Description and URL
- License Information
NAME TAG Licence Licence used for distrubution of your component
Licence Url The licence url
- License Information
- Developer Information
NAME TAG name Name of Developer
email Developer's email
organization Name of Company
organizationUrl Company's Website
- Developer Information
- Source Control Management Information
NAME TAG Connection scm connection to your source code
Developer Connection scm connection to your source code
URL URL for a web front end to your SCM system
Now Lets have a look at my completed POM
4.0.0
org.jpedal
FooBar
6.2.25
jar
${project.groupId}:${project.artifactId}
https://www.idrsolutions.com/foobar/
LGPL license, Version 3.0
https://www.gnu.org/licenses/lgpl.txt
IDRSolutions
contact2007@idrsolutions.com
IDRSolutions
https://www.isrdolutions.com
scm:git:git@github.com:IDRSolutions/maven-FooBar-src.git
scm:git:git@github.com:IDRSolutions/maven-FooBar-src.git
git@github.com:IDRSolutions/maven-FooBar-src.git
org.eclipse.birt.runtime.3_7_1
org.mozilla.javascript
1.7.2
jar
bouncycastle
bcprov-jdk16
140
jar
bouncycastle
bcmail-jdk16
140
jar
UTF-8
1.8
1.8
org.apache.maven.plugins
maven-gpg-plugin
sign-artifacts
verify
sign
org.sonatype.plugins
nexus-staging-maven-plugin
1.6.3
true
ossrh
https://oss.sonatype.org/
19375019933d12
true
org.apache.maven.plugins
maven-source-plugin
attach-sources
jar
org.apache.maven.plugins
maven-javadoc-plugin
attach-javadocs
jar
-Xdoclint:none
Note that I have some additional tags in my POM i.e Dependencies and Plugin. If your project depends on some other jars, you need to specify them in the dependencies tag. Also as I mentioned earlier, you need to supply the javadocs and source, and sign your artifact.
In my build tag, I also added some plugins which will generate the source and javadoc for me. I also added two plugins which will sign and upload my artifact to the Nexus staging repository. We will look in details about these two plugins.
Signing Your Artifact with PGP/GPG
You need to sign your artifact so when people download it, they can be sure they are downloading the original artifact. You will need to download GPG if you do not already have. You can get it from here. Once downloaded, you will need to generate a passphrase, sign, generate key pair and distribute your public key. You can Find a guide here.
Setting up Credentials for SonaType Nexus Repository
In order to deploy our artifact to the Nexus Repository I added the nexus-staging-maven-plugin to my build tag in the POM. Also there are some configuration you need to add to our setting.xml which can be found in your .m2 directory.Note you need to create it if it does not exist. Your settings.xml should look like this
ossrh
your_username
your_password
At this stage, you are ready to deploy to SonaType Nexus repository. Open Command/Terminal and navigate to your maven project and type in mvn clean deploy
. You will prompted to enter your passphrase. Once done, this should upload your artifact to SonaType Nexus repository. It takes a while for it to be synced to Maven Central.
Hopefully you have found this quick guide useful.
Our software libraries allow you to
Convert PDF to HTML in Java |
Convert PDF Forms to HTML5 in Java |
Convert PDF Documents to an image in Java |
Work with PDF Documents in Java |
Read and Write AVIF, HEIC, WEBP and other image formats |
stagingProfileID should not be in the POM, it is specific to a specific project.
Thanks Ernest, it works just fine!
unable to proprely read the pom.xml and other xml files