Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0

Repository is one of the fondamental maven concept. It's simple to understand but fair usage request a bit of practise.

You should have a clearer idea of repository management best practises through the following examples and counterexamples.

Initial configuration

This configuration come with maven without doing anything.

The "simple project" pom

Extended usage

Without repository manager 

Take a look on the "extended project" pom.

With repository manager


The "extended project" pom don't change, we just add mirrors section in the settings.xml (M2_HOME/conf/settings.xml or ~/.m2/settings.xml).
Take a look on the Mirrors definitions in settings.xml
 

Complex usage

Counterexamples

Single repo mirroring multiple repositories

(warning) THIS IS A COUNTEREXAMPLE

Mirror repository defined in place of original repository.

(warning) THIS IS A COUNTEREXAMPLE

Annexes

pom.xml

Simple project

Code Block
<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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.apache.maven.example.repository-management</groupId>
  <artifactId>initial</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>Simple repository example</name>
</project>

Extended project

Code Block
<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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.apache.maven.example.repository-management</groupId>
  <artifactId>extended</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>Extended usage of repository example</name>

  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.cargo</groupId>
        <artifactId>cargo-maven2-plugin</artifactId>
        <version>0.3-SNAPSHOT</version>
      </plugin>
    </plugins>
  </build>

  <dependencies>
    <dependency>
      <groupId>org.mortbay.jetty</groupId>
      <artifactId>jetty</artifactId>
      <version>6.1.6</version>
    </dependency>
  </dependencies>

  <repositories>
    <repository>
      <id>codehaus</id>
      <name>Codehaus Release Repo</name>
      <url>http://dist.codehaus.org/</url>
    </repository>
    <repository>
      <id>codehaus-snapshot</id>
      <name>Codehaus Snapshot Repo</name>
      <url>http://snapshots.repository.codehaus.org</url>
      <releases>
        <enabled>false</enabled>
      </releases>
    </repository>
  </repositories>

  <pluginRepositories>
    <pluginRepository>
      <id>codehaus</id>
      <name>Codehaus Release Repo</name>
      <url>http://repository.codehaus.org</url>
    </pluginRepository>
    <pluginRepository>
      <id>codehaus-snapshot</id>
      <name>Codehaus Snapshot Repo</name>
      <url>http://snapshots.repository.codehaus.org</url>
    </pluginRepository>
  </pluginRepositories>

</project>

 (info) Note that some repository declarations are useless:

  • Jetty is now available on central repository so you can remove
Code Block
<repository>
      <id>codehaus</id>
      <name>Codehaus Release Repo</name>
      <url>http://dist.codehaus.org/</url>
    </repository>
  • Project only need snapshot version of cargo plugin so you can remove
Code Block
<pluginRepository>
      <id>codehaus</id>
      <name>Codehaus Release Repo</name>
      <url>http://repository.codehaus.org</url>
    </pluginRepository>
  •  The project don't have any dependencies on snapshot version of codehaus artefacts so you can remove
Code Block
<repository>
      <id>codehaus-snapshot</id>
      <name>Codehaus Snapshot Repo</name>
      <url>http://snapshots.repository.codehaus.org</url>
      <releases>
        <enabled>false</enabled>
      </releases>
    </repository>

 Advanced project


Settings.xml including repository mirrors definitions


Code Block
<settings>
  <mirrors>
    <mirror>
      <id>codehaus-mirror</id>
      <mirrorOf>codehaus</mirrorOf>
      <name>Codehaus Release Repo Mirror</name>
      <url>http://[repository-manager-url]/codehaus-mirror/</url>
    </mirror>
    <mirror>
      <id>codehaus-snapshot</id>
      <mirrorOf>codehaus</mirrorOf>
      <name>Codehaus Snapshot Repo Mirror</name>
      <url>http://[repository-manager-url]/codehaus-snapshot/</url>
    </mirror>
  </mirrors>
</settings>