Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven Best Practices

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?

like image 635
Jeff Storey Avatar asked Jun 14 '09 22:06

Jeff Storey


1 Answers

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</url>
    </snapshotRepository>
    <repository>
      <id>nexusRelease</id>
      <name>Nexus Release Repository</name>
      <url>http://nexus.local:8081/nexus/content/repositories/releases</url>
    </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

like image 195
mrm Avatar answered Nov 16 '22 02:11

mrm