Setting up Multiple Repositories

There are two different ways that you can specify the use of multiple repositories. The first way is to specify in a POM which repositories you want to use:

  1. <project>
  2. ...
  3. <repositories>
  4. <repository>
  5. <id>my-repo1</id>
  6. <name>your custom repo</name>
  7. <url>http://jarsm2.dyndns.dk</url>
  8. </repository>
  9. <repository>
  10. <id>my-repo2</id>
  11. <name>your custom repo</name>
  12. <url>http://jarsm2.dyndns.dk</url>
  13. </repository>
  14. </repositories>
  15. ...
  16. </project>

The repositories element is inherited so you would usually specify the repositories to use for a group of projects by defining a repositories element at the top of your inheritance chain.

NOTE: You will also get the standard set of repositories as defined in the Super POM.

The other way you can specify the use of multiple repositories by creating a profile in your ${user.home}/.m2/settings.xml file like the following:

  1. <settings>
  2. ...
  3. <profiles>
  4. ...
  5. <profile>
  6. <id>myprofile</id>
  7. <repositories>
  8. <repository>
  9. <id>my-repo2</id>
  10. <name>your custom repo</name>
  11. <url>http://jarsm2.dyndns.dk</url>
  12. </repository>
  13. </repositories>
  14. </profile>
  15. ...
  16. </profiles>
  17.  
  18. <activeProfiles>
  19. <activeProfile>myprofile</activeProfile>
  20. </activeProfiles>
  21. ...
  22. </settings>

If you specify repositories in profiles you must remember to activate that particular profile! As you can see above we do this by registering a profile to be active in the activeProfiles element.

You could also activate this profile on the command like by executing the following command:

  1. mvn -Pmyprofile ...

In fact the -P option will take a CSV list of profiles to activate if you wish to activate multiple profiles simultaneously.

Note: The settings descriptor documentation can be found on the Maven Local Settings Model Website.