猿问

Maven 无法下载,因为 Maven Central 出现 PKIX 错误

我已经在我的机器上使用 maven 好几个月了,然后我开始从 maven central 收到 PKIX 错误,这阻止我下载适当的依赖项。


> mvn compile

[INFO] Scanning for projects...

Downloading from central: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starter-parent/2.1.7.RELEASE/spring-boot-starter-parent-2.1.7.RELEASE.pom

[ERROR] [ERROR] Some problems were encountered while processing the POMs:

[FATAL] Non-resolvable parent POM for com.test:testproject:0.0.1-SNAPSHOT: Could not transfer artifact org.springframework.boot:spring-boot-starter-parent:pom:2.1.7.RELEASE from/to central (https://repo.maven.apache.org/maven2): sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target and 'parent.relativePath' points at no local POM @ line 5, column 10

Maven 的完整调试输出似乎没有提供任何附加信息。我使用Spring Initializr

上的生成器创建了 pom ,没有任何其他选项或依赖项。

  <?xml version="1.0" encoding="UTF-8"?>

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">

        <modelVersion>4.0.0</modelVersion>

        <parent>

            <groupId>org.springframework.boot</groupId>

            <artifactId>spring-boot-starter-parent</artifactId>

            <version>2.1.7.RELEASE</version>

            <relativePath/> <!-- lookup parent from repository -->

        </parent>

        <groupId>com.test</groupId>

        <artifactId>testproject</artifactId>

        <version>0.0.1-SNAPSHOT</version>

        <packaging>war</packaging>

        <name>test</name>

        <description>Demo project for Spring Boot</description>

什么提供了临时解决办法:

  • 使用相同的pom文件在其他机器上编译

  • 更改我的settings.xml以指向私人镜像

  • 添加标志以忽略证书错误。

尽管这些解决方法都不是必要的。

什么似乎不起作用:

  • 手动将证书安装到 cacerts

  • 重新安装 Java 和 Maven

  • 删除.m2目录(包括settings.xml)

使用手动更新
指定信任库-Djavax.net.ssl.trustStore=$JAVA_HOME/jre/lib/security/cacerts似乎可以解决问题。我不确定为什么 Maven 默认找不到这个文件以及如何修复它。

米琪卡哇伊
浏览 270回答 4
4回答

慕标5832272

如果您使用代理,则已在 Maven 设置 xml 中添加配置<settings>..&nbsp; &nbsp; <proxies>&nbsp; &nbsp; &nbsp; &nbsp; <proxy>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <id>mycompany</id>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <active>true</active>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <protocol>https</protocol>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <host>10.203.13.45</host>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <port>8080</port>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <username>COMPANY\USER</username>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <password>PASSWORD</password>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <nonProxyHosts>127.0.0.1|localhost</nonProxyHosts>&nbsp; &nbsp; &nbsp; &nbsp; </proxy>&nbsp; &nbsp; &nbsp; &nbsp; <!-- -->&nbsp; &nbsp; </proxies>&nbsp; &nbsp;.</settings>

缥缈止盈

在 Mac 上通过 Homebrew 安装的 Maven 3.6.1 或 Oracle Java 8_221 似乎存在问题。它似乎没有正确获取默认信任库 (cacerts)。手动指定信任库将起作用。为了解决我的问题,我只是将我的 MVN_HOME 更改为旧版本 3.6.0(97c98ec64a1fdfee7767ce5ffb20918da4f719f3; 2018-10-24T14:41:47-04:00)并安装了 AdoptOpenJDK8,一切都很好。

翻阅古今

如果您使用代理,则已在 Maven 设置 xml 中添加配置<settings>..&nbsp; &nbsp; <proxies>&nbsp; &nbsp; &nbsp; &nbsp; <proxy>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <id>mycompany</id>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <active>true</active>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <protocol>https</protocol>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <host>10.203.13.45</host>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <port>8080</port>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <username>COMPANY\USER</username>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <password>PASSWORD</password>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <nonProxyHosts>127.0.0.1|localhost</nonProxyHosts>&nbsp; &nbsp; &nbsp; &nbsp; </proxy>&nbsp; &nbsp; &nbsp; &nbsp; <!-- -->&nbsp; &nbsp; </proxies>&nbsp; &nbsp;.</settings>

侃侃尔雅

配置您的 settings.xml 以使用 http 而不是 https 作为 maven 中央存储库应该有所帮助<settings>&nbsp; &nbsp;.&nbsp; &nbsp;.&nbsp; &nbsp;.&nbsp; <mirrors>&nbsp; &nbsp; <mirror>&nbsp; &nbsp; &nbsp; &nbsp; <id>central-no-ssl</id>&nbsp; &nbsp; &nbsp; &nbsp; <name>Central without ssl</name>&nbsp; &nbsp; &nbsp; &nbsp; <url>http://repo.maven.apache.org/maven2</url>&nbsp; &nbsp; &nbsp; &nbsp; <mirrorOf>central</mirrorOf>&nbsp; &nbsp; </mirror>&nbsp; </mirrors>&nbsp; &nbsp;.&nbsp; &nbsp;.&nbsp; &nbsp;.</settings>
随时随地看视频慕课网APP

相关分类

Java
我要回答