Bhaskar
Bhaskar

Reputation: 7523

maven repository proxy confusion

I am using maven 3.0 ( with nexus setup ) for building my projects and am getting build failures :

Caused by: org.sonatype.aether.transfer.ArtifactNotFoundException: Could not find artifact directory:apacheds-core:jar:${apacheds_version} in central (http://localhost:8081/nexus/content/repositories/central)
at org.sonatype.aether.connector.wagon.WagonRepositoryConnector$4.wrap(WagonRepositoryConnector.java:945)
at org.sonatype.aether.connector.wagon.WagonRepositoryConnector$4.wrap(WagonRepositoryConnector.java:940)

My basic confusion is : When maven sees a dependency in the pom.xml , how does it go about looking for artifacts in remote repositories ?

My current understanding is :

  1. It will first look in the local repo ( .m2/repository ).

  2. If it does not find there , then it will try to search the repository specified in settings.xml under repository tag. Question : Does it try all the repositories mentioned . or Just the first one ? Below I have mentioned 5 repos : does maven search all these one by one or just the first one ?

<repositories> <repository> <id>central</id> <url>http://localhost:8081/nexus/content/repositories/central</url> </repository> <repository> <id>remote</id> <url>http://localhost:8081/nexus/content/repositories/remote-proxy-nexus-central</url> </repository> <repository> <id>thirdParty</id> <url>http://localhost:8081/nexus/content/repositories/thirdparty</url> </repository> <repository> <id>codehaus</id> <url>http://localhost:8081/nexus/content/repositories/codehaus-snapshots</url> </repository> <repository> <id>public</id> <url>http://localhost:8081/nexus/content/groups/public</url> </repository> </repositories>

My last confusion is about proxies section in the settings.xml. What are these locations :

 <proxy>
  <id>remote-proxy-nexus-central</id>
  <active>true</active>
  <protocol>http</protocol>
  <host>repo1.maven.org/maven2</host>
  <port>8080</port>

</proxy>

Upvotes: 0

Views: 4457

Answers (2)

Manfred Moser
Manfred Moser

Reputation: 29912

The correct setup for using Maven with Nexus is documented in the book Repository Management with Nexus. The sample settings.xml is here. Read the description and note that you need to add the overrides for the central repository to enable snapshots.

Once you have done that you do NOT configured a proxy in your settings.xml since it will be available in your local network without a proxy (typically). Instead you configure the proxy settings in Nexus so that it in turn can get out to the repositories like Central that you are proxying. The global proxy configuration is documented here and if required you can also configure specifics per proxy repository e.g. if you need a username/password for a repository you are proxying because it is private..

Upvotes: 0

Eldad Assis
Eldad Assis

Reputation: 11045

I can tell you we use a local Nexus and have all our users have the following in their settings.xml:

<mirror>
    <id>our-mirror</id>
    <name>Org Public Mirror</name>
    <url>http://host/nexus/content/groups/public</url>
    <mirrorOf>*</mirrorOf>
</mirror>

This causes any call by maven to go to Nexus to get a dependency. You are right about maven first looking in local .m2.

Nexus proxies many repositories and has a union of them all (for the maven processes calling it). This means that a developer's local maven knows only of a single repository: Nexus. Nexus will serve all the needed dependencies id they are in one of its proxied/hosted repositories.

As for Proxy, we have an organization proxy, but the Nexus is in the org (it has the proxy configured to allow access to the outer world), so maven does not need this specific configuration.

I hope this gives you some information to get started.

I strongly urge you to look into Nexus/Maven related configurations at: http://www.sonatype.org/

Upvotes: 1

Related Questions