views:

863

answers:

2

Hi, I have a couple of questions about maven best practices and managing repositories.

In my environment, I do not want to go out to the central maven repository but rather store everything in an internal repository. Should I just require each user to put the information in settings.xml file that disables using the snapshots or releases from the maven repository or should this be in a POM file?

Also, I would like to have users all go to the same corporate repository. Should this repository info be put in the pom or in settings.xml? If it's in the pom, how will maven know to go to the repository since it needs to already know where the repository is to get the pom?

thanks, Jeff

+3  A: 

In a large project, it is best to have several repositories.

  1. The company proxy/cache will store donwloaded jars locally so that the company does not become dependent on the availability of external sites. It is accessed like a normal repository but it is a gateway to the public repositories.

  2. The company repository for released libraries is restricted, it contains internal libraries. These are frameworks that are "promoted" from the project repositories to the company repository because they can be useful for all projects.

  3. Project repositories contain artifacts used by the project. It can contain sub project artifacts and so on. Every developer in a project should be able to publish something in here.

Where you put the settings is a matter of taste. I put these things in the settings.xml. Because if the address of the internal repositories change you would otherwise have to modify the projects.

Bruno Ranschaert
This is all correct — I'd recommend looking into nexus (http://nexus.sonatype.org/) for a good solution to all the above.
Dominic Mitchell
Thanks. I've been using Apache's Archiva for its simplicity, but I'll be looking into Nexus as well. We're on a pretty small project right now, just trying to get these things in place early on.
Jeff Storey
+1 on Nexus. It's super easy to set up and operate.
Ken Liu
+3  A: 

Step one: Install nexus on a server in your LAN. It's excellent -- easy to install (really, just a couple minutes!) and solid. We have ~50 engineers and many CI servers banging on it all day and it's been stable for many months. Let's say you installed it on a server called "nexus.local" in your DNS.

Step two: Copy the settings.xml from http://www.sonatype.com/books/nexus-book/reference/maven-sect-single-group.html, fix the hostname as necessary, commit it to your source code system, and tell all your developers to copy it into their ~/.m2/settings.xml.

Step three: Set up your project's pom.xml properly. You'll want a "parent POM" that defines a "distributionManagement" section that looks something like this:

  <distributionManagement>
    <snapshotRepository>
      <id>nexusSS</id>
      <name>Nexus Snapshot Repository</name>
      <url>http://nexus.local:8081/nexus/content/repositories/snapshots&lt;/url&gt;
    </snapshotRepository>
    <repository>
      <id>nexusRelease</id>
      <name>Nexus Release Repository</name>
      <url>http://nexus.local:8081/nexus/content/repositories/releases&lt;/url&gt;
    </repository>
  </distributionManagement>

Step four: Enable "mvn deploy" -- go to your nexus UI ( something like http://nexus.local:8081/nexus ), click users, click "deployment", and give it a password. Then edit your ~/.m2/settings.xml and add this:

<settings>
  ...
  <servers>
    <server>
      <id>nexus</id>
      <username>deployment</username>
      <password>PASSWORD</password>
    </server>
  </servers>
</settings>

Check that it works by running "mvn deploy", and you should have installed your project's artifacts into nexus.

Step five: Read this excellent documentation for maven: http://www.sonatype.com/products/maven/documentation/book-defguide

mrm