Pages

Saturday, August 20, 2016

Nexus-Maven Integration

In this article we will see how we can integrate Maven with nexus and push our artifacts to the nexus repository.

1. Install and configure maven.
2. Once maven is configured , a local repository is created. The maven local repository is a local folder that is used to store all your project’s dependencies (plugin jars and other files which are downloaded by Maven). In simple, when you build a Maven project, all dependency files will be stored in your Maven local repository.

By default, Maven local repository is default to .m2 folder:
  1. Unix/Mac OS X – ~/.m2
  2. Windows – C:\Documents and Settings\{your-username}\.m2 
The local repository contains a settings.xml file which contains the configuration dertails.

3. Make changes to the settings.xml file for making our artifacts go to the Nexus repository.
There will 2 users ID admin for admin operations and deployment for deploy operations.

Add the below content to the ~/.m2/setting.xml as

Add the nexus Mirror with the location where nexus is running as,

  <mirrors>
    <mirror>
      <id>nexus</id>
      <mirrorOf>*</mirrorOf>
      <name>Human Readable Name for this Mirror.</name>
      <url>http://puppet.jas.com:8081/nexus/content/groups/public</url>
    </mirror>
  </mirrors>

Add a server location which  Specifies the authentication information to use when connecting to a particular server, identified by

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

4. Once the changes are done. let’s try to build a artifact and push to the nexus. Create a maven application or Download the javaee7-simple-sample application from the GITHUB location https://github.com/javaee-samples/javaee7-simple-sample

Add the distribution Management element to the pom.xml file as

 <distributionManagement>
        <repository>
            <id>nexus</id>
            <name>Internal Releases</name>
            <url>
http://puppet.jas.com:8081/nexus/content/repositories/releases/</url>
        </repository>
       <snapshotRepository>
            <id>nexus</id>
            <name>Internal Snapshot Releases</name>
            <url>
http://puppet.jas.com:8081/nexus/content/repositories/snapshots/</url>
        </snapshotRepository>
   </distributionManagement>

In the URL’s, add the URL where the nexus Repository is running.

5. Once the changes are done. Run the “mvn clean deploy” command 

No comments :

Post a Comment