Thursday, 6 September 2012

How To Add An External Repository In A Maven pom.xml?

By default, a maven project has access to the local repository and the central repository (see here for an introduction to maven concepts). It is possible to reference additional external repositories in the pom.xml to have access to its artifacts.
For example, it is currently not possible to access the following artifact from the central repository:
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-test-mvc</artifactId>
    <version>1.0.0.M1</version>
    <scope>test</scope>
</dependency>
One should access it from: http://repo.springsource.org/libs-milestone. This can be achieved by adding the following to your pom.xml:
<project>
    ...
    <repositories>
        <repository>
            <id>spring.test-mvc</id>
            <url>http://repo.springsource.org/libs-milestone</url>
        </repository>
    </repositories>
</project>