6

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?

Dror Bereznitsky
  • 20,048
  • 3
  • 48
  • 57
Brendon Dugan
  • 2,138
  • 7
  • 31
  • 65
  • Which guides have you already tried? What were your issues/errors with those three repositories? – Paul Grime Apr 11 '13 at 17:55
  • 1
    Since you found thee of them, it might make sense to look at the comparison matrix - http://docs.codehaus.org/display/MAVENUSER/Maven+Repository+Manager+Feature+Matrix – JBaruch Apr 13 '13 at 19:01
  • There are other people here in SO who common on how to use something as simple as a shared DropBox folder as a private, shared repo. Maybe help. – Andrew Mackenzie Jan 21 '14 at 22:07

3 Answers3

13

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.

Nathaniel Waisbrot
  • 23,261
  • 7
  • 71
  • 99
  • 3
    I would suggest NOT to use the war but rather the installer that included Nexus and Jetty in it (tar.gz or zip file). I am glad you like the book btw. In terms of distinguishing between pro and oss ... thats on the website. And we constantly add more things to oss as well as pro and things change so the book does not make a big distinction. – Manfred Moser Apr 12 '13 at 05:06
  • @ManfredMoser If you've got a page explaining the pros and cons of using the installer, that'd be very interesting. I'm making pretty simple use Nexus OSS, and my experience has been that the war is simpler to upgrade and requires less thinking on my part. It's a pretty small difference, though. – Nathaniel Waisbrot Apr 12 '13 at 05:22
  • The upgrade with the bundle is trivial (http://www.sonatype.com/books/nexus-book/reference/install-sect-upgrading.html). The main advantage is that we test with the bundle all the time and pro runs on the bundle. All commercial installations use it including jboss, ossrh and so on. The war is not supported for pro so you are pretty much on your own. You also get better performance out of the bundled jetty.. – Manfred Moser Apr 12 '13 at 05:42
  • I got the same problem, and it is solved used your sample code. – BlueDolphin Dec 26 '13 at 01:40
  • I cant find the hosted eval guide anymore but here is the source. https://github.com/sonatype/nexus-book/blob/nexus-2.14.x/chapter-eval.asciidoc – Manfred Moser Jun 14 '17 at 05:53
7

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.

Sri Sankaran
  • 8,120
  • 4
  • 38
  • 47
  • You should NOT add a repo server as repository. This only give you a small benefit. It is much better to set it up as a global mirror. See more here http://www.sonatype.com/books/nexus-book/reference/config.html – Manfred Moser Apr 12 '13 at 05:11
  • @ManfredMoser I agree Nexus is more than a repository. In fact I even **say** that! However the original question was just for a way to host "internal" JARs. Ergo my response. That said, I respectfully disagree with your assertion "you should NOT add a repo server as a repository". That **is** the fundamental purpose of the `repository` setting. – Sri Sankaran Apr 12 '13 at 13:10
  • Well .. you are misunderstanding the best practice to use the mirror section in the settings.xml file. If you add a repository in the settings file you and not using the mirror section all your requests for components will still go to the Central repository AND you repo manager. That way you reduce performance and loose the benefit of caching the components from Central in Nexus. And the repo server still will be a repository to Maven. In addition you can no add lots of other repositories to your public group and all developers will get access without needing to change their settings file. – Manfred Moser Apr 12 '13 at 16:14
  • @ManfredMoser Point taken. I was simply disputing the "should NOT" part of your original comment. Yeah, I was picking nits. – Sri Sankaran Apr 16 '13 at 15:40
4

I would suggest to use the Nexus evaluation guide (latest available version is 2.13 now) that comes with the Nexus Pro Installer, but also works with Nexus Open Source for the simple use cases of proxying and deploying components.

The examples are also available on github and include setups for Maven, Ant/Ivy and Gradle. Once you have a look at the examples and read the guide you will be able to set up your projects in the same way easily.

And of course if there is any problems you can always ask on the mailing list or chat with the developers on hipchat

Manfred Moser
  • 29,539
  • 13
  • 92
  • 123
  • The hipchat was the key! I was having a combination of Maven caching issues, a missing repository proxy for a third-party plugin, and a little old fashioned stupidity. – Brendon Dugan Apr 12 '13 at 15:30
  • I saw the chat in the log. Well done. I am glad Ben and Kelly could help you. – Manfred Moser Apr 12 '13 at 16:18
  • https://www.sonatype.com/books/nexus-book/reference/eval.html this link is not working @ManfredMoser – tymbark Jun 13 '17 at 07:55
  • Seems like the guide was taken offline with 2.14 forwards. Here is the 2.13 version which will still apply to newer releases. http://books.sonatype.com/nexus-book/2.13/reference/eval.html – Manfred Moser Jun 17 '17 at 04:12