Maven – Can download jar file using maven+local repo, but not using maven+nexus

mavennexus

I'm trying to integrate nexus into a maven project and having a problem, hoping someone here can help out.

Initially I had my maven settings.xml file to use a local repository only:

<settings>
  <localRepository>C:\\r</localRepository>
  ...
</settings>

This works fine and all dependencies for my project are downloaded into the local repository. I verified this by deleting the directory for the maven-settings-2.2.1 artifact and running mvn -U dependency:list again:

Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/maven-settings/2.2.1/maven-settings-2.2.1.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/maven-settings/2.2.1/maven-settings-2.2.1.pom (3 KB at 11.3 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/maven-settings/2.2.1/maven-settings-2.2.1.jar
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/maven-settings/2.2.1/maven-settings-2.2.1.jar (48 KB at 509.5 KB/sec)

It is seen above that the pom.xml and .jar file for the maven-settings-2.2.1 artifact have been downloaded.

Next I tried configuring my maven project to point to a nexus repository that I have set up:

<settings>
  <localRepository>C:\\r</localRepository>
  <mirrors>
    <mirror>
  <id>nexus</id>
  <mirrorOf>*</mirrorOf>
  <url>http://<server>:<port>/nexus/content/groups/public</url>
</mirror>
  </mirrors>
  ...
</settings>

I deleted the maven-settings-2.2.1 artifacts from my local repository, and ran mvn -U dependency:list again:

Downloading:  http://:/nexus/content/groups/public/org/apache/maven/maven-settings/2.2.1/maven-settings-2.2.1.pom
Downloaded: http://:/nexus/content/groups/public/org/apache/maven/maven-settings/2.2.1/maven-settings-2.2.1.pom (3 KB at 17.0 KB/sec)
Downloading: http://:/nexus/content/groups/public/org/apache/maven/maven-settings/2.2.1/maven-settings-2.2.1.jar

[ERROR] Failed to execute goal on project : Could not resolve dependencies for project : The following artifacts could not be resolved: org.apache.maven:maven-settings:jar:2.2.1: Could not find artifact org.apache.maven:maven-settings:jar:2.2.1 in nexus (http://:/nexus/content/groups/public) -> [Help 1]

This time, nexus can download the pom.xml file the maven-settings-2.2.1 artifact, but cannot download the .jar file. I checked on the nexus server and when I browse the remote contents of the 'central' repository I can see the maven-settings-2.2.1 artifacts (both pom.xml and .jar file), but in the nexus local storage I see the pom.xml file only.

So I looked at the nexus documentation (see http://books.sonatype.com/nexus-book/reference/maven-sect-single-group.html) and set up my maven settings with a nexus profile as suggested:

<settings>
  ... as before ...
  <profiles>
    <profile>
      <id>nexus</id>
      <repositories>
        <repository>
          <id>central</id>
          <url>http://central</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <id>central</id>
          <url>http://central</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>
  </profiles>
</settings>

Again I deleted any local copy of maven-settings-2.2.1 artifact, and ran mvn -U dependency:list:

Downloading: http://:/nexus/content/groups/public/org/apache/maven/maven-settings/2.2.1/maven-settings-2.2.1.pom
Downloaded: http://:/nexus/content/groups/public/org/apache/maven/maven-settings/2.2.1/maven-settings-2.2.1.pom
Downloading: http://:/nexus/content/groups/public/org/apache/maven/maven-settings/2.2.1/maven-settings-2.2.1.jar

[ERROR] Failed to execute goal on project : Could not resolve dependencies for project : The following artifacts could not be resolved: org.apache.maven:maven-settings:jar:2.2.1: Could not find artifact org.apache.maven:maven-settings:jar:2.2.1 in nexus (http://:/nexus/content/groups/public) -> [Help 1]

As before, the pom.xml was downloaded from nexus, but not the .jar file. And as before, when I inspect the local storage on the nexus server, the pom.xml file is present, but not the .jar file.

As a sanity test, I removed the nexus configuration from my maven settings.xml, removed the maven-settings-2.2.1 artifacts from my local repository, and tried again:

Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/maven-settings/2.2.1/maven-settings-2.2.1.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/maven-settings/2.2.1/maven-settings-2.2.1.pom
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/maven-settings/2.2.1/maven-settings-2.2.1.jar
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/maven-settings/2.2.1/maven-settings-2.2.1.jar

This time, both the pom.xml and `.jar file were downloaded directly.

So I am not sure what I need to do to get around this issue: when using a local repository and get maven to download dependencies directly, I can download both the pom.xml and .jar files for the maven-settings-2.2.1 artifact. When I add my nexus server into the mix, only the pom.xml is downloaded by nexus.

Is this a nexus server configuration issue, or a maven configuration issue?

Best Answer

First you misunderstood the meaning of Local Repository.

Even you are using Nexus, you are still having a local repository. Local repository is simply a repository in your own machine to store all artifacts that Maven will use for build. In case a dependency is required and is not available in local repository, Maven will contact the remote repository to try to get the dependency. Once it is get, it is put in local repo so that Maven can continue its build process.

One thing you may have misunderstood too: Even you removed the nexus setting, Maven is still going to download from a default remote repository, which is so-called Maven Central (http://repo.maven.apache.org/maven2).

The whole problem , I believe, is simply you are not setting up your Maven correct to make use of the nexus. From your quoted config :

<url>http://<server>:<port>/nexus/content/groups/public</url>

to the error message in Maven:

[ERROR] ...  Could not find artifact ... in nexus (http://:/nexus/content/groups/public) -> [Help 1]

The hostname and port of nexus is simply not correctly setup.

Fix that and everything should work

If such problem is because you masked the data, then the problem will be related to your installation of nexus. Go in the console site of Nexus, and verify if you have correctly setup the proxies, by browsing remote files of the proxies you set up. Check if you have Maven central as one of the proxies in the 'public' proxy group too