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.
This configuration come with maven without doing anything.

The "simple project" pom.

Take a look on the "extended project" pom.

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.
THIS IS A COUNTEREXAMPLE
THIS IS A COUNTEREXAMPLE
<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>
|
<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>
|
Note that some repository declarations are useless:
<repository>
<id>codehaus</id>
<name>Codehaus Release Repo</name>
<url>http://dist.codehaus.org/</url>
</repository>
|
<pluginRepository>
<id>codehaus</id>
<name>Codehaus Release Repo</name>
<url>http://repository.codehaus.org</url>
</pluginRepository>
|
<repository>
<id>codehaus-snapshot</id>
<name>Codehaus Snapshot Repo</name>
<url>http://snapshots.repository.codehaus.org</url>
<releases>
<enabled>false</enabled>
</releases>
</repository>
|
<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>
|