Skip to content

Deploy XSpec artifact to Maven Central

AirQuick edited this page Oct 20, 2020 · 6 revisions

Here are the instructions to set up and deploy an XSpec artifact to Maven Central for the first time.

@cirulls has already done this setup on his machine to release previous versions of XSpec so the only command to execute prior to a release is:

mvn -Prelease deploy

After the successful completion of the command, the new artifact should appear within few minutes under repo1.maven.org and within few hours under search.maven.org.

Instructions for first time setup

@cirulls can help other contributors to do this setup for future releases (as the setup contains secrets it cannot be shared on GitHub).

The POM file to deploy the XSpec artifact to Maven Central is located here.

Note that you cannot deploy directly to Maven Central and you have to deploy first to another repository which will be automatically synchronized with Maven Central. For example, use https://oss.sonatype.org, create an account there to get a login and password.

First, declare the authentication in your ~/.m2/settings.xml :

<settings>
 <servers>
  <server>
   <id>ossrh</id>
   <username>your_username</username>
   <password>your_password</password>
  </server>
 </server>
</settings>

Then, you'll need to sign artifacts to make them deployable. Maven has a plugin to sign artifacts but it requires GPG keys. Depending on your OS, create your GPG key and deploy it to a server (see these instructions). To make life simpler, create a key with no expiration date.

Once your key created, declare it in your ~/.m2/settings.xml:

<settings>
 <servers ... />
 <profiles>
  <profile>
   <id>ossrh</id>
   <activation>
    <activeByDefault>true</activeByDefault>
   </activation>
   <properties>
    <gpg.executable>gpg2</gpg.executable>
    <gpg.passphrase>your_gpg_passphrase</gpg.passphrase>
   </properties>
  </profile>
 </profiles>
</settings>

This will allow you to use your key to sign artifacts from Maven. Your keys are simple files that can be moved from a computer to another.

Then, you must register your groupId. You should own a domain name and declare a groupId based on this domain name. Create an issue on Sonatype JIRA (you may need to sign up for an account if you don't have one already). In the Issue type field, choose New Project. Be careful, it's not a new project, it's your groupId root, so create a new groupId root. @cmarchand owns marchand.top so for example he created an issue for top.marchand. Once the issue is processed (usually within 48h max), you'll get the URL of the repositories where you can deploy.

An open source artifact must have certain values otherwise it'll be refused. These are:

  • description
  • url
  • scm

Add these values to your pom.xml.

Afterwards, you need to declare what you deploy. For example for XSpec releases declare this in the pom.xml:

<distributionManagement>
 <repository>
  <id>ossrh</id>
  <url>URL sent in JIRA issue</url>
 </repository>
</distributionManagement>

If you want to deploy snapshots, add a <snapshotRepository /> with URL sent back by the JIRA issue.

Then, declare a profile to generate sources (as XSpec is an open-source project), javadoc, and to sign artifacts:

<profiles>
 <profile>
  <id>release</id>
  <build>
   <plugins>
    <plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-gpg-plugin</artifactId>
     <version>1.6</version>
     <executions>
      <execution>
       <id>sign-artifacts</id>
       <phase>verify</phase>
       <goals>
        <goal>sign</goal>
       </goals>
      </execution>
     </executions>
    </plugin>
    <plugin>
     <groupId>org.sonatype.plugins</groupId>
     <artifactId>nexus-staging-maven-plugin</artifactId>
     <version>1.6.7</version>
     <extensions>true</extensions>
     <configuration>
      <serverId>ossrh</serverId>
      <nexusUrl>https://oss.sonatype.org/</nexusUrl>
      <autoReleaseAfterClose>true</autoReleaseAfterClose>
     </configuration>
    </plugin>
   </plugins>
  </build>
 </profile>
</profiles>

Finally, when you want to deploy, just type :

mvn -Prelease deploy

When you deploy, your artifact goes to a staging repository where it is checked. If it does not pass checks, you'll only be able to remove it. If you added true in nexus-staging-maven-plugin, it will automatically be moved to a release repository on Sonatype (repository synchronized with Maven Central). Otherwise, you have to type:

mvn -Prelease org.sonatype.plugins:nexus-staging-maven-plugin:staging:release

or use the Nexus web application to convert you artifact to a release.

This article is translated and adapted from @cmarchand original article in French.

Clone this wiki locally