How to upload your Java artifact to Maven Central

Maven

How to upload your Java artifact to Maven Central.

Previously I wrote an article about hosting an article about hosting an article 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

To host an artifact on Maven Central 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 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
      NAMETAG
      groupId
       org.jpedal
      artifactId
      FooBar
      Version
         1.0

 

    • Project Name, Description and URL
      NAMETAG
      name
      org.jpedal:FooBar
      description
         Description or your product
      url
        Your company URL

 

    • License Information
      NAMETAG
      Licence
      Licence used for distrubution of your component
      Licence Url
      The licence url

 

    • Developer Information
      NAMETAG
      name
      Name of Developer
      email
       Developer's email
      organization
       Name of Company
      organizationUrl
      Company's Website

 

  • Source Control Management Information
    NAMETAG
    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

<!--?xml version="1.0" encoding="UTF-8"?-->
 
    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 when uploading to Maven Central.
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.

If you’re a first-time reader, or simply want to be notified when we post new articles and updates, you can keep up to date by social media (Twitter, Facebook and Google+) or the Blog RSS.

Related Posts:

The following two tabs change content below.

Ernest Duodu

Developer at IDRSolutions
Ernest is a developer at IDRSolutions. He focuses mainly on our JavaFX PDF Viewer implementation. He was a speaker at JavaOne 2014, where he did a joint session titled "Lessons learnt developing a NetBeans PDF viewer plugin in JavaFX". Aside programming, he also enjoys a wide variety of hobbies which includes sky-diving, photography, exercising and listening to music.
Ernest

About Ernest Duodu

Ernest is a developer at IDRSolutions. He focuses mainly on our JavaFX PDF Viewer implementation. He was a speaker at JavaOne 2014, where he did a joint session titled "Lessons learnt developing a NetBeans PDF viewer plugin in JavaFX". Aside programming, he also enjoys a wide variety of hobbies which includes sky-diving, photography, exercising and listening to music.

2 thoughts on “How to upload your Java artifact to Maven Central

  1. MeowingTwurtle

    stagingProfileID should not be in the POM, it is specific to a specific project.

  2. Alessio

    Thanks Ernest, it works just fine!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>