Maven Repositories

From NovaOrdis Knowledge Base
Jump to navigation Jump to search

External

Internal

Overview

A repository is used to hold build artifacts, dependencies of various types and plugins. There are only two types of repositories: local and remote.

A local repository is a cache of the remote downloads and also contains temporary build artifacts.

A remote repository is accessed over a network protocol such as http:// or even file://. They may be set up by other organizations, or by your own organization in order to share artifacts between different development teams. If a dependency is not available in the local repository, Maven attempts to find it in a remote repository and cache it locally if found.

Where are Repositories Declared?

The Local Repository

The location of the local repository, if differs from the default $HOME/.m2/repository, is usually declared in settings.xml as <localRepository>.

Remote Repositories

The right place to declare additional repositories is, according to the Maven orthodoxy, the settings.xml file. Repositories can also be declared in pom.xml, but usually that type of information does not belong in there.

Adding a Remote Repository

Both "http://" and "file://" work.

A generic http repository:

...
<repositories>
    <repository>
        <id>my-site</id>
        <url>http://myserver/repo/</url>
    </repository>
</repositories>
...

This is an example of adding a local EAP repository:

...
<repositories>
    <repository>
        <id>jboss-datagrid-6.6.0-maven-repository</id>
        <url>file:///Users/ovidiu/runtime/jboss-datagrid-6.6.0-maven-repository</url>
    </repository>
</repositories>
...

Password-Protected Repositories

In case the remote repository is password protected, the authentication configuration is mapped to Maven configuration as follows:

1. Encrypt the password as follows and store the encrypted value to use at the next step:

mvn --encrypt-password <password-in-clear>

For more details about encrypting passwords and the master password, see:

mvn --encrypt-password

2. Declare a <server> in the <servers> section of the relevant file, (which may be settings.xml or pom.xml. The most common - and recommended - option is to declare all this in a profile in settings.xml.

<servers>
   <server>
       <id>myServer</id>
       <username>my_login</username>
       <password>...</password>
       ...
   </server>
</servers>

3. Use the server's id, such declared, in the repository declaration:

<repositories>
    <repository>
        <id>myServer</id>
        <name>My Protected Repository</name>
        ...
     </repository>
 </repositories>

Elements

<id>

<name>

<url>

<layout>

"default" or "legacy".

<releases>/<snapshots>

Contains the policy for releases or snapshots.

<releases>|<snapshots>
    <enabled>false</enabled>
    <updatePolicy>always</updatePolicy>
    <checksumPolicy>warn</checksumPolicy>
</releases>>|<snapshots>

<enabled>

true or false whether this repository is enabled for the respective type of artifact.

<updatePolicy>

Specifies how often updates should attempt to occur. Maven will compare the local POM's timestamp, as stored in a repository's maven-metadata file, to the remote. The choices are: "always", "daily", "interval:X" where X is an integer in minutes or "never".

<checksumPolicy>

When Maven deploys files to the repository, it also deploys corresponding checksum files. Your options are to ignore , fail , or warn on missing or incorrect checksums.

Using Maven Repositories when Compiling JBoss EAP

Note that in some cases, multiple maven repositories are required, as with JDG 7 which relies on EAP 7:

...
<profiles>
    <profile>
        <id>jdg7</id>
        <repositories>
            <repository>
                <id>jboss-eap-7.0.0.GA-maven</id>
                <url>file:///Users/ovidiu/runtime/jboss-eap-7.0.0.GA-maven-repository/maven-repository</url>
            </repository>
            <repository>
                <id>jboss-datagrid-7.0-maven</id>
                <url>file:///Users/ovidiu/runtime/jboss-datagrid-7.0.0-maven-repository/maven-repository</url>
             </repository>
        </repositories>
        ...
    </profile>
</profiles>
...

A full example on how to configure that is available here:

https://github.com/NovaOrdis/playground/blob/master/jboss/infinispan/hotrod-client/pom.xml