Adding a project to Maven Central - tooltwist/documentation GitHub Wiki

To make a Java based library or project available to the public, the best place to place it is in Maven central. From there people can include it in their projects simply by referencing it as a dependancy in their pom.xml file.

NOTE: placing a projects on Maven Central makes it Open Source.
Don't follow these instructions for projects containing proprietary code.

To search for a project, go to http://search.maven.org.

The Central Repository is maintained by the guys at Sonatype. A user account needs to be created with them (we already have one for tooltwist), and we notify them each time a new project is added by submitting a ticket on their issues management system.

See https://docs.sonatype.org/display/Repository/Sonatype+OSS+Maven+Repository+Usage+Guide

Signing Files

Maven Central requires that repository files are signed. Phil maintains the keychain used to sign ToolTwist projects, and the account with Sonatype.

See https://docs.sonatype.org/display/Repository/How+To+Generate+PGP+Signatures+With+Maven

On OSX a few problems occur when the deployment process wants to ask the user for the passphrase. To get around this, upgrade to Maven 3.0.4+ and add these settings to ~/.m2/settings.xml.

<!-- Settings for GPG -->
<profiles>
  <profile>
    <id>gpg</id>
    <properties>
      <gpg.executable>gpg2</gpg.executable>
      <gpg.passphrase>passwordGoesHere</gpg.passphrase>
    </properties>
  </profile>
</profiles>
<activeProfiles>
  <activeProfile>gpg</activeProfile>
</activeProfiles>

To upgrade Maven, you may be able to use Homebrew (http://mxcl.github.io/homebrew/) but I encountered errors (2013-05-17).

brew install maven

To get around this problem I manually upgraded Maven:

  1. Download from http://maven.apache.org/download.cgi

  2. Find the current location of Maven, and install the new version alongside. Be sure to change file ownerships and remove quarantine attributes from the download process (xattr -dr com.apple.quarantine *).

    $ ls -l /usr/share/java
    total 8
    drwxr-xr-x 3 root wheel 102 23 Jun 2012 Stubs
    drwxr-xr-x 5 root wheel 170 21 Jun 2012 Tools
    drwxr-xr-x 7 root wheel 238 21 Jun 2012 ant-1.8.2
    drwxr-xr-x 8 root wheel 272 21 Jun 2012 derby-10.8.1.2
    drwxr-xr-x 9 root wheel 306 26 Jul 2012 junit-4.10
    lrwxr-xr-x 1 root wheel 20 26 Jul 2012 junit.jar -> junit-4.10/junit.jar
    drwxr-xr-x 9 root wheel 306 7 Jan 03:56 maven-3.0.3
    drwxr-xr-x 9 root wheel 306 17 May 17:58 maven-3.0.5 <<<<<<<<< THIS IS NEW <<<<<<<

  3. Replace the symbolic link to the current version

    $ ls -l /usr/share/maven
    lrwxr-xr-x 1 root wheel 16 17 May 17:55 /usr/share/maven -> java/maven-3.0.3

    $ rm /us/share/maven
    $ ln -s java/maven-3.0.5 /usr/share/maven

Deploying the project

In terms of how to set up your pom.xml, the easiest thing is to copy the pom.xml from the xdata project and make modifications. The following are a few common build commands:

Removes files created by a previous build:

mvn clean

Build the project and install it in the local repository (~/.m2/repository/...)

mvn install

Install the current snapshot to Maven Central (not certain about this):

mvn deploy

Build the project, submit it to Github and ad a git tag for the version number, and increment the version number in the pom.xml.

mvn release:prepare

If all goes well with the release:prepare, the project can be submitted to Maven Central using release:perform.

mvn release:perform

The Staging Repository

The previous build options submit the project to the staging repository. To properly release the new version of the project, you need to close the staging repository and then release the project. A dashboard to maintain projects and artifacts is provided at https://oss.sonatype.org. Follow the steps in section 8a of the guide to promote from 'staged' to 'released'.

In addition, if it's the first time you've promoted the project you'll need to submit a ticket to Sonatype. See Section 9 of the guide.

⚠️ **GitHub.com Fallback** ⚠️