2013-07-11 89 views
0

我正试图将nexus集成到maven项目中,并遇到问题,希望这里有人能帮忙。可以使用maven + local repo下载jar文件,但不能使用maven + nexus?

起初,我有我的行家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) 

可以看出上面的maven-settings-2.2.1神器pom.xml.jar文件已被下载。

接下来我想配置我的Maven项目指向,我已经建立了一个关系库:我删除了我的本地库的maven-settings-2.2.1文物

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

,并再次运行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本地存储器中,我只能看到pom.xml文件。

所以我看着关系文件(见http://books.sonatype.com/nexus-book/reference/maven-sect-single-group.html),并设置我有关系的个人资料行家设置的建议:

<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文件。

作为一个理智的测试,我删除从我的行家settings.xml承上启下的配置,除去从我的本地库的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文件直接下载。

所以我不知道我需要做什么来解决这个问题:使用本地存储库时,让行家直接下载的依赖,我可以同时下载pom.xml.jar文件的maven-settings-2.2.1神器。当我添加我的nexus服务器时,只有pom.xml被nexus下载。

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

回答

1

首先你误解了Local Repository的含义。

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

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

我相信整个问题只是你没有设置你的Maven正确使用该连接。从你引述的配置:

<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中心作为“公共”代理组中的代理人之一

+0

感谢您的回复。我正在从本地回购库中删除工件,以便Maven根据配置不得不直接从Maven Central获取这些工件,或者间接通过我的连接服务器获取这些工件。所以我认为我正确理解了这个概念? –

+0

上面引用中的“http://:/ nexus/...”是一个剪切-n粘贴错误,它应该是“http://,server>:/nexus/...”。它可以工作,因为其他工件正在下载,而不是maven-settings-2.2.1 jar文件。 –

+0

它的工作原理是因为您之前已经在本地仓库中构建并下载过它,因为Maven可以在本地仓库中找到它们,因此它不会下载它。只是为了确定......你是否真的看到了''或者你只是掩盖了它?我希望你告诉我,这实际上是真正的主机名和端口号。而且,你有没有试图确定你的nexus回购实际上有效?我提到了一种方法来验证 –

相关问题