Apr 24 2006
Setting up a Maven2 Internal Repository.
This is going to be a very very dull post unless you are trying to figure out how to set up an internal company repository for maven2. If you are, and you are desperately looking for information on how you do this, then welcome.
I have just spent the morning trying to get a communal internal repository set up for our development environment, and it turns out that there is next to no information available on how to do it. This is mainly because it’s very easy, but still, it would have been a more productive morning if there was a web page somewhere explaining it.
Maven manages your dependencies, and can automatically download various jar files and so on for you. Telling it “I need to use Junit†for example will cause it to download Junit, and put it on your classpath. It gets files it downloads from a repository.
By default Maven will talk to two repositories. One is the central repository maintained at the Maven site, and the other is a local copy, which will be in the .m2 directory of your home directory.
We wanted to have a something that falls between these two settings; something that all our developers can download from, but isn’t publicly accessible. We use various commercial third party libraries and making them available to the entire world is clearly bad.
It turns out that a maven repository is just a directory somewhere, and that’s about it. In order to use it there are very few steps you need to do.
- Choose a directory
- Make sure its accessible via some network protocol to everyone who needs it (i.e. serve it via http or ftp or something
- Put the libraries you need in the directory, in a specific format.
- Set up your maven builds to read from the repository
- (optional) set up your maven builds to deploy your repository
I will assume you know how to do the first two steps. A point of interest about the second step is that to deploy anything to the repository you must use a protocol that supports writing. I suggest scp. In fact I have made the repository available via scp for deployment, and http(s) for reading (makes authentication easier). Our server is going to change only to https soon, and I need to figure out how to get maven to support self signed certificates. At the moment it just dies.
To put existing libraries into the repository, use the maven deploy command.
To set up your build to read from the repository add the following xml to your pom.xml file:
The URL must be accessible for read permission, but write is not required.
Finally, to get your maven build to deploy to the repository, add in:
Obviously there are lots of things you can tweak with the xml elements etc. But hopefully this will get you far enough along for the maven2 website’s documentation on xml elements to be of use.





