I don't like rants about Maven so I'm going to be as descriptive as I can.
There are 2 ways to add new repositories to Maven, that is to say to tell Maven about where it should look for dependencies.
- In the POM.
- In the user or global settings.
POM
In the POM, you add a repository by declaring it inside the <build> <repositories> <repository>
element.
<project>
...
<repositories>
<repository>
<id>my-repo1</id>
<name>your custom repo</name>
<url>http://jarsm2.dyndns.dk</url>
</repository>
<repository>
<id>my-repo2</id>
<name>your custom repo</name>
<url>http://jarsm2.dyndns.dk</url>
</repository>
</repositories>
...
</project>
User / Global settings
This is done by modifying the ~/.m2/settings.xml
file (for user settings) or $M2_HOME/conf/settings.xml
(for global settings). In this case, repositories are added to a profile that is made active by default:
<settings>
...
<profiles>
...
<profile>
<id>myprofile</id>
<repositories>
<repository>
<id>my-repo2</id>
<name>your custom repo</name>
<url>http://jarsm2.dyndns.dk</url>
</repository>
</repositories>
</profile>
...
</profiles>
<activeProfiles>
<activeProfile>myprofile</activeProfile>
</activeProfiles>
...
</settings>
Hopefully, this is clear enough.
- For a local repository, the URL is:
file://path/to/repo
- For a remote repository, the URL is:
http[s]://path/to/repo
Now, it is considered a best practice to put this information in the settings instead of the POM because this information will typically be the same for every project you have. This is corporate information and we need to treat it globally, not per project. If you need it per project, then you can add it to your POM. The result will be the same.
Repositories can be further configured by specifying the release or snapshot mode, update policy, etc. Please refer to the documentation about this.
Mirror
In your edit, you are using a mirror. To configure a mirror to only be used for a specific repository, you can have the following configuration in the settings:
<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">
...
<mirrors>
<mirror>
<id>my-wonderful-mirror</id>
<url>http://myserver:8080/nexus/content/groups/public</url>
<mirrorOf>id-of-your-repository</mirrorOf> <!-- this is the ID of the repository, i.e. what is inside settings > profiles > profile > repositories > repository > id -->
</mirror>
</mirrors>
...
</settings>
This way, you can configure a mirror for the remote repository and not for the local one.