首页 文章

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

提问于
浏览
0

我正在尝试将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)

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

接下来,我尝试将我的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服务器,当我浏览'central'存储库的远程内容时,我可以看到 maven-settings-2.2.1 工件( pom.xml.jar 文件),但在nexus本地存储中,我只看到 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直接下载依赖项时,我可以为 maven-settings-2.2.1 工件下载 pom.xml.jar 文件 . 当我将nexus服务器添加到混合中时,只有 pom.xml 被nexus下载 .

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

1 回答

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

相关问题