Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven Internal Repository, Is it Really This Hard?

I have several projects which use Maven and I would like to run an internal repository on my work network. I have several libraries which are from third parties and cannot be released into the wild, as well as a few libraries of our own which need to be available within the network (including to our TeamCity CI Server) but cannot be deployed outside the network. After a bit of research, I found three main recommendations on how to accomplish this: Archiva, Artifactory, and Nexus. I have tried each, and have failed to achieve a successful build of any of my projects using the internal repositories created by any of them.

This leads me to believe that I am misunderstanding something or doing something wrong. Does anyone know of a tutorial that will walk me through setting up and internal Maven repository and integrate it with my project?

like image 467
Brendon Dugan Avatar asked Apr 11 '13 17:04

Brendon Dugan


People also ask

How does Maven repository work?

A repository in Maven holds build artifacts and dependencies of varying types. There are exactly two types of repositories: local and remote: the local repository is a directory on the computer where Maven runs. It caches remote downloads and contains temporary build artifacts that you have not yet released.

How does Maven know which repository?

Maven just goes through the list and looks into all the repositories. It is not possible to tie dependencies to special repositories.

What is the Maven central repository?

Introduction to Maven Central Repository. Maven repository is a directory where all the dependencies such as jars, library files, plugins, or other artifacts that will be required by the projects are stored.

How much space is recommended for Maven's local artifact repository?

How much disk space does the Maven Repository consume? Approximately 10MB is required for the Maven installation itself.


2 Answers

I have only worked with Nexus, but I found it very easy to install:

  1. Go to http://www.sonatype.org/nexus/go to download the OSS version
  2. Get the 'WAR' distribution
  3. Install the servlet in my installation of Tomcat, via the Web Application Manager

At that point, I can visit http://myserver:8080/nexus to see everything working.

For a superficial setup, I add the default password to my settings.xml:

    <servers>
            <server>
                    <id>my-snapshots</id>
                    <username>admin</username>
                    <password>admin123</password>
            </server>
            <server>
                    <id>my-releases</id>
                    <username>admin</username>
                    <password>admin123</password>
            </server>
    </servers>

and in my POM file:

    <distributionManagement>
            <snapshotRepository>
                    <id>my-snapshots</id>
                    <name>My internal repository</name>
                    <url>http://myserver:8080/nexus/content/repositories/snapshots</url>
            </snapshotRepository>
            <repository>
                    <id>my-releases</id>
                    <name>My internal repository</name>
                    <url>http://myserver:8080/nexus/content/repositories/releases</url>
            </repository>
    </distributionManagement>

To go beyond this, the learning curve jumps up quite a bit, but I found Sonatype's online books to be pretty good. Repository Management with Nexus is the one for understanding what you can do with the repository server. The only thing I found tricky is that some of the info applies only to their commercial software and they don't work too hard to advertise the difference.

like image 71
Nathaniel Waisbrot Avatar answered Sep 29 '22 15:09

Nathaniel Waisbrot


Repository managers like Archiva and Nexus are more than just an internal repository. They serve as proxies that obviate reaching out to Maven central or other external repository.

For just an internal repository all you need is a network or HTTP accessible location that has the structure of a Maven repository. Then you refer to it as another repository in your settings file.

<repository>
  <id>my-internal-repo</id>
  <url>http://myrepo.mycompany.com/</url>
</repository>

See more in Maven's documentation at http://maven.apache.org/guides/introduction/introduction-to-repositories.html.

like image 45
Sri Sankaran Avatar answered Sep 29 '22 14:09

Sri Sankaran