Maven 构建失败 -- DependencyResolutionException

Maven Build Failure -- DependencyResolutionException

我正在安装一个具有 Maven 依赖项的包,并在我尝试清理它时收到 DependencyResolutionException。 克隆后,我导航到目录并 运行 以下内容以无错误地安装它:

mvn install:install-file -Dfile=./lib/massbank.jar -DgroupId=massbank  -DartifactId=massbank -Dversion=1.0 -Dpackaging=jar
mvn install:install-file -Dfile=./lib/metfusion.jar -DgroupId=de.ipbhalle.msbi  -DartifactId=metfusion -Dversion=1.0 -Dpackaging=jar

然后:

mvn clean package 

控制台输出如下:

[INFO] Scanning for projects...
[INFO] 
[INFO] --------------------< MassBank2NIST:MassBank2NIST >---------------------
[INFO] Building MassBank2NIST 0.0.2-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.450 s
[INFO] Finished at: 2021-04-07T01:08:28-04:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project MassBank2NIST: Could not resolve dependencies for project MassBank2NIST:MassBank2NIST:jar:0.0.2-SNAPSHOT: Failed to collect dependencies at edu.ucdavis.fiehnlab.splash:core:jar:1.8: Failed to read artifact descriptor for edu.ucdavis.fiehnlab.splash:core:jar:1.8: Could not transfer artifact edu.ucdavis.fiehnlab.splash:core:pom:1.8 from/to maven-default-http-blocker (http://0.0.0.0/): Blocked mirror for repositories: [EBI (http://www.ebi.ac.uk/intact/maven/nexus/content/repositories/ebi-repo/, default, releases+snapshots), releases (http://gose.fiehnlab.ucdavis.edu:55000/content/groups/public, default, releases+snapshots)] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException

如有必要,我可以 post 调试日志开关的输出,但它很长。我也可以 post pom.xml,但据我所知,它指的是所需的存储库。

我搜索过类似的 post,但 none 似乎包含相同系列或类似的错误。谁能帮我破译这些错误?

谢谢!

Maven release note for version 3.8.1:

中明确提到错误“存储库的镜像被阻止”

How to fix when I get a HTTP repository blocked?

If the repository is defined in your pom.xml, please fix it in your source code.

If the repository is defined in one of your dependencies POM, you’ll get a message like:

[ERROR] Failed to execute goal on project test: Could not resolve dependencies for project xxx: Failed to collect dependencies at my.test:dependency:version -> my.test.transitive:transitive:version: Failed to read artifact descriptor for my.test.transitive:transitive:jar:version: Could not transfer artifact my.test.transitive:transitive:pom:version from/to maven-default-http-blocker (http://0.0.0.0/): Blocked mirror for repositories: [blocked-repository-id (http://blocked.repository.org, default, releases+snapshots)]

他们继续提供一些避免问题的方法:

Options to fix are:

  • upgrade the dependency version to a newer version that replaced the obsolete HTTP repository URL with a HTTPS one,

  • keep the dependency version but define a mirror in your settings.

另外,我想,更简单、更短期的选择是将您的 Maven 版本回滚到 3.8.1 之前的任何版本。

使用 apache-maven-3.6.3,它只使用 http

https://downloads.apache.org/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.zip

您不必降级 Maven。这里发生的是,从 3.8.1 开始,Maven 带有一个默认配置来阻止所有 HTTP(不安全)存储库。最好的方法是升级您的存储库并确保它们安全 (HTTPS)。

但是,您可以通过将此镜像添加到 ~/.m2/settings.xml:

来告诉 Maven 允许从不安全的存储库下载
<mirror>
  <id>insecure-repo</id>
  <mirrorOf>external:http:*</mirrorOf>
  <url>http://www.ebi.ac.uk/intact/maven/nexus/content/repositories/ebi-repo/</url>
  <blocked>false</blocked>
</mirror>

blocked 设置为 false 将解决您的问题。请注意,上面的代码片段假定 www.ebi.ac.uk 的存储库镜像所有不安全的 HTTP 存储库(这就是 external:http:* 的意思)。

您还可以取消阻止单个存储库。例如,JasperSoft 存储库是不安全的,我使用以下命令解锁它:

<mirror>
  <id>jaspersoft-third-party-mirror</id>
  <mirrorOf>jaspersoft-third-party</mirrorOf>
  <url>http://jaspersoft.jfrog.io/jaspersoft/third-party-ce-artifacts/</url>
  <blocked>false</blocked>
</mirror>

使用apache-maven-3.8.1,在~/.m2/settings.xml中添加以下内容可以解决该问题:

<mirrors>
  <mirror>
    <id>internal-repository</id>
    <name>Maven Repository Manager running on https://repo1.maven.org/maven2</name>
    <url>https://repo1.maven.org/maven2</url>
    <mirrorOf>*</mirrorOf>
  </mirror>
</mirrors>

参考这篇linkhttps://maven.apache.org/guides/mini/guide-mirror-settings.html了解错误发生的原因。

如果您无权访问 ~/.m2/settings.xml 因为您的构建由云处理 CI/CD 或者您想与您的团队成员共享此解决方案。最好的方法是在项目中创建自己的maven设置文件。

  1. 在您的项目中创建 .mvn 文件夹。
  2. .mvn 文件夹中创建 custom-settings.xml 文件并包含以下内容(在本例中,我们为 releases.java.net 镜像取消阻止 http 连接):
<settings xmlns="http://maven.apache.org/SETTINGS/1.2.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 http://maven.apache.org/xsd/settings-1.2.0.xsd">
    <mirrors>
        <mirror>
            <id>releases-java-net-http-unblocker</id>
            <mirrorOf>releases.java.net</mirrorOf>
            <name>releases.java.net</name>
            <url>http://maven.java.net/content/repositories/releases/</url>
            <blocked>false</blocked>
        </mirror>
    </mirrors>
</settings>
  1. .mvn 文件夹中创建 maven.config 文件,内容如下:
--settings ../.mvn/custom-settings.xml

或者你可以运行 mvn clean install --settings .mvn/custom-settings.xml.

打开文件 ${MAVEN_HOME}/conf/settings.xml

并注释这些行。

<mirror>
    <id>maven-default-http-blocker</id>
    <mirrorOf>external:http:*</mirrorOf>
    <name>Pseudo repository to mirror external repositories initially using HTTP.</name>
    <url>http://0.0.0.0/</url>
    <blocked>false</blocked>
</mirror>

apache-maven-3.6.3-bin 将解决 maven-default-http-blocker (http //0.0.0.0/) 被阻止的问题(为我修复)它对我有用

最终不得不降级到 mvn 3.5

brew 卸载 maven

安装 mvn 3.5 的说明可在

找到

https://formulae.brew.sh/formula/maven@3.5

我遇到了类似的问题,但使用的是 Vaadin。 有一个最简单的解决方案,就是将所有http://替换为https://

这是一个例子:

<repository>
    <id>vaadin-addons</id>
    <url>https://maven.vaadin.com/vaadin-addons</url>
</repository>

这是由于最新的 Maven 阻止了不安全的 HTTP 连接。一种可能性是向 maven settings.xml 添加一个镜像。最好的方法是更新 pom 文件以引用安全 HTTPS 存储库(如果可用)。例如,我在 pom.xml.

中的以下配置遇到了同样的问题
<repositories>
    <repository>
        <releases>
            <enabled>true</enabled>
            <updatePolicy>daily</updatePolicy>
            <checksumPolicy>ignore</checksumPolicy>
        </releases>
        <id>wso2-nexus</id>
        <url>http://maven.wso2.org/nexus/content/groups/wso2-public/</url>
    </repository>
</repositories>

我能够通过如下更新 URL 来解决问题。在这里,我提到了 HTTPS 存储库,它在我的案例中可用。

<url>https://maven.wso2.org/nexus/content/groups/wso2-public/</url>

对我来说,我不得不从 site 降级到旧版本 3.6.3 并且疯狂的问题消失了,希望 maven 社区可以解决这个问题而不需要我们对 settings.xml.