Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding maven nexus repo to my pom.xml

Tags:

maven

I have installed nexus on my local machine. I want my pom file to point to this repo. How can I add my custom repository to my pom.xml file?

like image 618
AndroidDev Avatar asked Jan 15 '13 08:01

AndroidDev


People also ask

Can we add repository in POM xml?

Putting non-standard repositories in the pom. xml file (which gets checked into source control) means every developer can build. But YES, your authentication for a repository server should be in your private settings. xml file.

What is the tag name which we will use to integrate Nexus repo details in POM xml?

6. pom. xml. In case of the project managed in Maven, package repository in which artifact is stored, should be specified using <distributionManagement> tag of pom.


2 Answers

From Maven - Settings Reference

The repositories for download and deployment are defined by the repositories and distributionManagement elements of the POM. However, certain settings such as username and password should not be distributed along with the pom.xml. This type of information should exist on the build server in the settings.xml.

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0                   http://maven.apache.org/xsd/settings-1.0.0.xsd">   ...   <servers>     <server>       <id>server001</id>       <username>my_login</username>       <password>my_password</password>       <privateKey>${user.home}/.ssh/id_dsa</privateKey>       <passphrase>some_passphrase</passphrase>       <filePermissions>664</filePermissions>       <directoryPermissions>775</directoryPermissions>       <configuration></configuration>     </server>   </servers>   ... </settings> 

id: This is the ID of the server (not of the user to login as) that matches the id element of the repository/mirror that Maven tries to connect to.

username, password: These elements appear as a pair denoting the login and password required to authenticate to this server.

privateKey, passphrase: Like the previous two elements, this pair specifies a path to a private key (default is ${user.home}/.ssh/id_dsa) and a passphrase, if required. The passphrase and password elements may be externalized in the future, but for now they must be set plain-text in the settings.xml file.

filePermissions, directoryPermissions: When a repository file or directory is created on deployment, these are the permissions to use. The legal values of each is a three digit number corrosponding to *nix file permissions, ie. 664, or 775.

Note: If you use a private key to login to the server, make sure you omit the element. Otherwise, the key will be ignored.

All you should need is the id, username and password

The id and URL should be defined in your pom.xml like this:

<repositories>     ...     <repository>         <id>acme-nexus-releases</id>         <name>acme nexus</name>         <url>https://nexus.acme.net/content/repositories/releases</url>     </repository>     ... </repositories> 

If you need a username and password to your server, you should encrypt it. Maven Password Encryption

like image 89
Philipp Sander Avatar answered Sep 19 '22 14:09

Philipp Sander


First of all I can highly recommend reading the Nexus book. It will explain the benefits of using a Maven repository manager.

There is a section on how to configure your Maven build to use Nexus:

  • http://www.sonatype.com/books/nexus-book/reference/config.html

This leads me to question why you altering your POM file? I suspect what you really want to do is setup Nexus as a remote repository mirror. This is done in your Maven settings file.

The following tells Maven use Nexus as your default repository (Instead of Maven Central)

<settings>   ..   ..   <mirrors>     <mirror>       <id>nexus</id>       <url>http://localhost:8081/nexus/content/groups/public</url>       <mirrorOf>central</mirrorOf>     </mirror>   </mirrors> 

This is desired behaviour since your Nexus repository is configured to cache artifacts retrieved from Central (which is good for build performance).

Note:

  • The "public" repository group could include other repositories proxied by your Nexus instance (Not just Maven Central). You probabily want this behaviour, as it centralizes all repository management. It just makes your build less portable for people outside of your organization.
like image 40
Mark O'Connor Avatar answered Sep 17 '22 14:09

Mark O'Connor