Last Updated: February 25, 2016
·
672
· robdbirch

Maven Repository in less than 15 minutes

This cheat sheet will enable you to setup a private Maven repository to store only your business libraries. It should take about 15 minutes with very little administrative hassle to set up and maintain.

Caveat Emptor

This is NOT the recommended practice for deploying a Maven repository. The main reason this is not the recommended installation practice is this installation does not take advantage of the Nexus servers ability to proxy, manage and cache other library assets from other repositories. There are an abundant number of voluminous documents and stackoverflow questions that will show the "correct way everybody should deploy a Maven repo". Here are some links to docs and discussions:

The above information and advice is excellent, and you're strongly encouraged to read through it for a proper understanding of Maven and deploying Maven repositories. But if you want to start using a Maven repo in short order then continue on.

15 Minute Install

  • Be sure Java 7 is installed
  • Download the Nexus OSS Server and unpack in the desired directory and create a symbolic link.

    $ ln -s nexus-2.11.X nexus
  • Starting the server

    $ cd /opt/nexus/nexus-2.11.X
    
    $ bin/nexus start
    
    $ tail -f logs/wrapper.log # if you want check the log
    • You might want to set it up as a service
    • Browsing the new Repository
      Web Repository URL: http://localhost:8081/nexus

      login: admin
      
      password: admin123
    • Don't forget to change the default admin user password in the Security -> Users menu item

    • Use the UI to browse the repository at the above url. Click on the Repositories tab and browse Snapshots and Releases.

  • User credentials to access repository

    • Developers need to add the following to the ~/.m2/settings.xml. This file may need to be created.
    • Administrator don't forget to use the UI to change the default deployment user password in the Security -> Users menu item
<settings>
    <servers>
        <server>
            <id>releases</id>
            <username>deployment</username>
            <password>deployment123</password>
        </server>
        <server>
            <id>snapshots</id>
            <username>deployment</username>
            <password>deployment123</password>
        </server>
        <server>
            <id>thirdparty</id>
            <username>deployment</username>
            <password>deployment123</password>
        </server>
    </servers>
</settings>
  • POM for deployment

Developers that push to the repository should add the following to the project POM to push to the Maven-Nexus repository.

<distributionManagement>
    <repository>
        <id>releases</id>
        <name>Internal Releases</name>
        <url>http://localhost:8081/nexus/content/repositories/releases</url>
    </repository>
    <snapshotRepository>
        <id>snapshots</id>
        <name>Internal Snapshots</name>
        <url>http://localhost:8081/nexus/content/repositories/snapshots</url>
    </snapshotRepository>
</distributionManagement>
  • POM for Dependencies

Developers that pull will add the following to the project POM for pulling dependent jars from the private Nexus-Maven repository

<repositories>
    <repository>
        <id>snapshots</id>
        <url>http://localhost:8081/nexus/content/repositories/snapshots</url>
    </repository>
    <repository>
        <id>releases</id>
        <url>http://localhost:8081/nexus/content/repositories/releases</url>
    </repository>
</repositories>
<dependency>
    <groupId>com.acme</groupId>
    <artifactId>FooBar</artifactId>
    <version>1.0-SNAPSHOT</version>
</dependency>