Friday, June 8, 2012

Deploying maven build artifacts to Nexus repository

To deploy the artifacts generated by your maven build to nexus repository, you need configure it in 2 files
1) Parent pom.xml
2) settings.xml

and also to prevent publishing password in settings.xml file, you need to configure password less ssh connection between your build machine and nexus repository


Pom.xml changes
Add distributionManagement section to your parent pom.xml and provide ID, name, url for various delivery types like snapshots, releases, site, etc.
Here is an example from our project




<distributionManagement>
   <repository>
<id>kms.distribution.releaserepository</id>
<name>DPM KMS Maven Release Repository</name>
<url>scp://my-repo.org/export/nexus/sonatype-work/nexus/storage/releases/</url>
<uniqueVersion>false</uniqueVersion>
   </repository>
   <snapshotRepository>
<id>kms.distribution.snapshotrepository</id>
<name>DPM KMS Maven Snapshot Repository</name>
<url>scp:// my-repo.org /export/nexus/sonatype-work/nexus/storage/snapshots/</url>
<uniqueVersion>false</uniqueVersion>
   </snapshotRepository>
           <site> 
            <id>kms.distribution.sitelocation</id>
            <name>DPM Maven Site location</name>
            <url>scp:// my-repo.org /export/nexus/sonatype-work/nexus/storage/rkm/site/</url> 
            </site>
</distributionManagement>

The above configuration dictates to copy kits using scp. There are other ways of delivering like http.
Also we created ID's like kms.distribution.releaserepository, kms.distribution.snapshotrepository, etc. The related entries needs to be made in settings.xml file

settings.xml changes
The settings.xml for a maven2 project can reside either in
1) ~/.m2/settings.xml or
2) MAVEN-INSTALLATION-LOCATION/conf/settings.xml

In settings .xml file add  <servers> tag and provide login credentials for nexus repository.

 <servers>

   <server>
        <id>kms.distribution.snapshotrepository</id>
        <username>maven</username>
    </server>
    <server>
        <id>kms.distribution.releaserepository</id>
        <username>maven</username>
    </server>
    <server>
        <id>kms.distribution.sitelocation</id>
        <username>maven</username>
    </server>

  </servers>


You can provide password using <password> tag. But it's not wise to share password in settings.xml.
Instead establish a password less ssh connection between your build server and nexus repo using public/private key generation.


After making above changes, run
mvn depoloy

which will deploy your artifacts in nexus repository.

1 comment:

Anonymous said...

correct the small mistakes happened in release part