简体   繁体   English

Maven神器无法解析; 试图从错误的存储库中解析工件

[英]Maven artifact cannot be resolved; attempting to resolve artifact from the wrong repository

After upgrading a dependency in my pom.xml, I received the following error when attempting to download the new artifact (Using maven command line mvn spring-boot:run in this case).在我的 pom.xml 中升级依赖项后,我在尝试下载新工件时收到以下错误(在本例中使用 maven 命令行mvn spring-boot:run )。

The following artifacts could not be resolved: io.github.bonigarcia:webdrivermanager:jar:3.8.1, org.zaproxy:zap-clientapi:jar:1.7.0: Could not find artifact io.github.bonigarcia:webdrivermanager:jar:3.8.1 in spring-milestone ( https://repo.spring.io/milestone )无法解析以下工件:io.github.bonigarcia:webdrivermanager:jar:3.8.1,org.zaproxy:zap-clientapi:jar:1.7.0:找不到工件 io.github.bonigarcia:webdrivermanager:jar: 3.8.1 在 spring-milestone ( https://repo.spring.io/milestone )

The error message is correct, that artifact does not exist in https://repo.spring.io/milestone .错误消息是正确的,该工件在https://repo.spring.io/milestone中不存在。 It does exists in Maven central ( https://repo.maven.apache.org/maven2 ), so why would Maven be looking for the artifact in the wrong repository?它确实存在于 Maven 中心 ( https://repo.maven.apache.org/maven2 ),那么为什么 Maven 会在错误的存储库中查找工件?

I do know that this is tied to my Maven settings (settings.xml) where I define a mirror to our internal Nexus repository.我知道这与我的 Maven 设置 (settings.xml) 相关联,我在其中定义了一个指向我们内部 Nexus 存储库的镜像。 When I remove the mirror, Maven successfully looks for and finds the artifact in Maven central.当我移除镜像时,Maven 成功地在 Maven Central 中查找并找到了工件。 What I don't understand is the mechanics of how things work when an artifact does not exist in Nexus, and why this mirror setting changes how an artifact is discovered for the first time.我不明白的是当 Nexus 中不存在工件时事情如何运作的机制,以及为什么这个镜像设置会改变第一次发现工件的方式。

From settings.xml..从 settings.xml..

<mirrors>
    <mirror>
        <id>Nexus</id>
        <name>Nexus Public Mirror</name>
        <url>https://myinternalnexushost.net/nexus/content/repositories/central</url>
        <mirrorOf>central</mirrorOf>
    </mirror>
</mirrors>

It's also noteworthy that this is a Spring Boot project.还值得注意的是,这是一个 Spring Boot 项目。 I don't define any repositories in my pom.xml, but since I'm specifying a spring boot parent pom I'm inheriting the following repositories:我没有在我的 pom.xml 中定义任何存储库,但是因为我指定了一个 spring boot 父 pom,所以我继承了以下存储库:

From Spring Boot parent pom来自 Spring Boot 父 pom

  <repositories>
    <repository>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <id>spring-milestone</id>
      <name>Spring Milestone</name>
      <url>https://repo.spring.io/milestone</url>
    </repository>
    <repository>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
      <id>spring-snapshot</id>
      <name>Spring Snapshot</name>
      <url>https://repo.spring.io/snapshot</url>
    </repository>
    <repository>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <id>rabbit-milestone</id>
      <name>Rabbit Milestone</name>
      <url>https://dl.bintray.com/rabbitmq/maven-milestones</url>
    </repository>
    <repository>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <id>central</id>
      <name>Central Repository</name>
      <url>https://repo.maven.apache.org/maven2</url>
    </repository>
  </repositories>

When you tell Maven to use a mirror, that mirror is used instead of the original repository.当您告诉 Maven 使用镜像时,将使用该镜像而不是原始存储库。

Which means when you mirror "central" you lose access to anything in Maven Central that's not in that mirror.这意味着当您镜像“中央”时,您将无法访问 Maven Central 中不在该镜像中的任何内容。

You usually define the repos under repositories and each of it has an identifier.您通常在存储库下定义repositories ,每个存储库都有一个标识符。 This identifier is then used for the mirrors.该标识符随后用于镜像。 In your config you mirror the repo with id central在您的配置中,您使用 id central镜像 repo

<mirrors>
    <mirror>
        <id>Nexus</id>
        <name>Nexus Public Mirror</name>
        <url>https://myinternalnexushost.net/nexus/content/repositories/central</url>
        <mirrorOf>central</mirrorOf>
    </mirror>
</mirrors>

As the repo https://repo.spring.io/ has another identifier it is not mirrored using central .由于 repo https://repo.spring.io/有另一个标识符,它没有使用central进行镜像。 So you have to define mirrors for each other repos as well, for example所以你也必须为彼此的回购定义镜像,例如

<mirrors>
    <mirror>
        <id>Nexus</id>
        <name>Nexus Public Mirror</name>
        <url>https://myinternalnexushost.net/nexus/content/repositories/central</url>
        <mirrorOf>central</mirrorOf>
    </mirror>
    <mirror>
        <id>Spring</id>
        <name>Nexus Public Mirror</name>
        <url>https://myinternalnexushost.net/nexus/content/repositories/spring-milestone</url>
        <mirrorOf>spring-milestone</mirrorOf>
    </mirror>
</mirrors>

See also theguidelines :另请参阅指南

With Repositories you specify from which locations you want to download certain artifacts, such as dependencies and maven-plugins.使用存储库,您可以指定要从哪些位置下载某些工件,例如依赖项和 maven 插件。 Repositories can be declared inside a project, which means that if you have your own custom repositories, those sharing your project easily get the right settings out of the box.存储库可以在项目内声明,这意味着如果您有自己的自定义存储库,那些共享您的项目的人可以轻松获得开箱即用的正确设置。 However, you may want to use an alternative mirror for a particular repository without changing the project files.但是,您可能希望在不更改项目文件的情况下为特定存储库使用备用镜像。

I generally would do the following which makes things a bit easier to maintain我通常会做以下事情,这使得事情更容易维护

  • create a "remote" repo for each of the required repos in Nexus为 Nexus 中的每个必需的回购创建一个“远程”回购
  • create a "group" repo in Nexus which contains all remote repos在 Nexus 中创建一个包含所有远程仓库的“组”仓库

then you have to specify only this in your settings.xml那么你必须在你的settings.xml中只指定这个

<mirrors>
    <mirror>
        <id>Nexus</id>
        <name>Nexus Public Mirror</name>
        <url>https://myinternalnexushost.net/nexus/content/repositories/maven-group</url>
        <mirrorOf>*</mirrorOf>
    </mirror>
</mirrors>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM