Google

Jul 13, 2014

Maven with Nexus for distribution management

Q. What is Nexus?
A. Nexus is a central repository manager that stores and organizes binary software components for use in development, deployment, and provisioning. Nexus becomes the deployment destination for the components that are created by your organization using Maven.

  • You can publish your own library or project JARs, WARs, EARs etc. both sanapshot and release versions using Nexus Pro. 
  • You can host your own repository to support your custom components and share those components with other users or computers on your network. 
  • Once your components are placed in the repository - they can be made available to all developers securely using access controls and SSL.
  • You can search for artifacts.




Q. How to configure maven to publish artifacts to Nexus?
A. To configure a Maven project to publish artifacts to Nexus, you'll need to add a distributionManagement element to your project's pom.xml.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.mycompany</groupId>
    <artifactId>mycompany-parent</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>pom</packaging>

    <distributionManagement>
        <snapshotRepository>
            <id>mycompany-snapshots</id>
            <name>mycompany Snapshots</name>
            <url>http://myhost:8080/nexus/content/repositories/mycompany-snapshots</url>
            <uniqueVersion>true</uniqueVersion>
        </snapshotRepository>
  <repository>
            <id>mycompany-releases</id>
            <name>mycompany Releases</name>
            <url>http://myhost:8080/nexus/content/repositories/mycompany-releases</url>
        </repository>
    </distributionManagement>

</project>


The child projects or modules will refer to the parent project

<parent>
  <groupId>com.mycompany</groupId>
  <artifactId>mycompany-parent</artifactId>
  <version>1.0.0</version>
</parent>


If your Nexus server requires authentication, you will also need to place your credentials in ~/.m2/settings.xml in a servers element.

<servers>
  <server>
    <id>deployment</id>
    <username>deployment</username>
    <password>deployment123</password>
  </server>
</servers>


Once you've configured your project's pom.xml and your Maven Settings, you can deploy your project with

mvn deploy


which will execute the build up to the deploy phase. When you run a deploy with a project that has a snapshot version, Maven will deploy to the repository defined in snapshotRepository, and when you run a build with a project that has a release version it will deploy to the repository defined in the repository element.


Q. What is the difference between snapshot versions and release versions?
A. The "SNAPSHOT" term means that the build is a snapshot of your code at a given time, which means downloading 1.0-SNAPSHOT  today might give a different file than downloading it yesterday or tomorrow. When you are ready to release your project, you will change 1.0-SNAPSHOT to 1.0 in the pom.xml file. The 1.0 is the release version. After release, any new developmwent work will stat using  1.1-SNAPSHOT and so on.

Labels:

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

Links to this post:

Create a Link

<< Home