可以使用maven + local repo下载jar文件,但不能使用maven + nexus吗?

时间:2013-07-11 00:21:32

标签: maven nexus

我正在尝试将nexus整合到一个maven项目中并遇到问题,希望有人可以提供帮助。

最初我的maven settings.xml文件只能使用本地存储库:

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

这很好用,我项目的所有依赖项都下载到本地存储库中。我通过删除maven-settings-2.2.1工件的目录并再次运行mvn -U dependency:list来验证这一点:

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)

上面可以看到已下载pom.xml工件的.jarmaven-settings-2.2.1文件。

接下来,我尝试将我的maven项目配置为指向我已设置的nexus存储库:

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

我从本地存储库中删除了maven-settings-2.2.1工件,然后再次运行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 (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]

这次,nexus可以下载pom.xml文件maven-settings-2.2.1工件,但无法下载.jar文件。我检查了nexus服务器,当我浏览“中央”存储库的远程内容时,我可以看到maven-settings-2.2.1工件(pom.xml.jar文件),但是在nexus local中存储我只看到pom.xml文件。

所以我查看了nexus文档(请参阅http://books.sonatype.com/nexus-book/reference/maven-sect-single-group.html)并根据建议使用nexus配置文件设置我的maven设置:

<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>

我再次删除了maven-settings-2.2.1工件的任何本地副本,并运行了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]

和以前一样,pom.xml是从nexus下载的,而不是.jar文件。和以前一样,当我检查nexus服务器上的本地存储时,pom.xml文件存在,但不存在.jar文件。

作为一项完整性测试,我从我的maven settings.xml中删除了nexus配置,从我的本地存储库中删除了maven-settings-2.2.1工件,然后再次尝试:

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

这一次,pom.xml和`.jar文件都是直接下载的。

所以我不确定我需要做些什么来解决这个问题:当使用本地存储库并让maven直接下载依赖项时,我可以下载pom.xml.jar文件maven-settings-2.2.1神器。当我将nexus服务器添加到混合中时,只有nexus下载了pom.xml

这是nexus服务器配置问题还是maven配置问题?

1 个答案:

答案 0 :(得分:1)

首先,你误解了本地存储库的含义。

即使您使用的是Nexus,您仍然拥有本地存储库。本地存储库只是您自己机器中的存储库,用于存储Maven将用于构建的所有工件。如果需要依赖项并且在本地存储库中不可用,Maven将联系远程存储库以尝试获取依赖项。一旦获得,它将被放入本地仓库,以便Maven可以继续其构建过程。

你可能误解了一件事:即使你删除了nexus设置,Maven仍然会从默认的远程存储库下载,这就是所谓的Maven Central(http://repo.maven.apache.org/maven2)。

我认为,整个问题只是你没有设置你的Maven正确使用nexus。来自你引用的配置:

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

到Maven中的错误消息:

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

nexus的主机名和端口设置不正确。

解决这个问题,一切都应该有效

如果此类问题是因为您屏蔽了数据,那么问题将与您安装nexus有关。进入Nexus的控制台站点,通过浏览您设置的代理的远程文件,验证您是否正确设置了代理。检查您是否将Maven central作为“公共”代理组中的代理之一