简体   繁体   中英

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?

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.

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 .

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM