Saturday 28 May 2011

Add custom repository to maven and add a library (dependency) from this repository

If you add a dependency to your project's pom.xml file, everytime when you try to build your project maven tries to connect to maven's default libraries (http://repo1.maven.com ...) and returns with a error message which says it could not find source in maven default repositories. So: lets see how can you add your custom repositories to maven and dependencies to your projects.

Scenario: there is that myLib-200.jar with a groupId which is 'aliolcicode' under the http://repo.aliolci.com

1. You have to add that custom repository to your maven settings to inform maven that 'I use my custom repositories next to maven repositories'. To do this. open your maven settings file (click here to see how) and add these lines below, between 'mirrors' tags
in XML above the important part is the url part the others are definition of your custom repository.
<mirror>
<id>aliolci</id>
<name>aliolci code repository</name>
<url>http://repo.aliolci.com</url>
<mirrorof>*</mirrorof>
</mirror>
2. Add your dependency to your project. There is nothing special about this. Just add your dependency as usual into your projects pom.xml.
<dependencies>
<dependency>
<groupid>aliolcicode</groupid>
<artifactid>myLib</artifactid>
<version>200</version>
</dependency>
</dependencies>
That's it. Enjoy!

No comments: