我正试图将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配置问题?
感谢您的回复。我正在从本地回购库中删除工件,以便Maven根据配置不得不直接从Maven Central获取这些工件,或者间接通过我的连接服务器获取这些工件。所以我认为我正确理解了这个概念? –
上面引用中的“http://:/ nexus/...”是一个剪切-n粘贴错误,它应该是“http://,server>:/nexus/...”。它可以工作,因为其他工件正在下载,而不是maven-settings-2.2.1 jar文件。 –
它的工作原理是因为您之前已经在本地仓库中构建并下载过它,因为Maven可以在本地仓库中找到它们,因此它不会下载它。只是为了确定......你是否真的看到了':'或者你只是掩盖了它?我希望你告诉我,这实际上是真正的主机名和端口号。而且,你有没有试图确定你的nexus回购实际上有效?我提到了一种方法来验证 –