Maven 错误 Could not transfer artifact org.apache.maven.plugins:maven-source-plugin:pom:3.0.1 from/to central

Maven Errror Could not transfer artifact org.apache.maven.plugins:maven-source-plugin:pom:3.0.1 from/to central

我正在尝试使用 Maven 编译我的代码,出现以下错误,

环境

我正在使用 azure devops 服务器并使用构建管道 Maven 错误无法传输工件 org.apache.maven.plugins:maven-source-plugin:pom:3.0.1 from/to central

2021-02-26T11:43:14.4764714Z [ERROR] Plugin org.apache.maven.plugins:maven-source-plugin:3.0.1 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-source-plugin:jar:3.0.1: Could not transfer artifact org.apache.maven.plugins:maven-source-plugin:pom:3.0.1 from/to central (https://repo.maven.apache.org/maven2): Transfer failed for https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-source-plugin/3.0.1/maven-source-plugin-3.0.1.pom ProxyInfo{host='12.3.4.59', userName='null', port=80, type='http', nonProxyHosts='null'}: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target -> [Help 1]

Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

根据报错信息:

Transfer failed for https://repo.maven.apache.org/maven2...unable to find valid certification path to requested target

它表明 Maven 正在尝试从位于 https://repo.maven.apache.org/maven2 的 Maven 中央存储库下载间接依赖项,这是一个 安全 HTTP 服务器 (HTTPS)。所以问题可能来自您的证书本身或您的网络。

对于证书,尝试https://repo.maven.apache.org/maven2并下载证书,然后将其添加到cacerts,使用命令:

keytool -import -alias example -keystore  .\cacerts -file example.cer

请尝试查看此线程中的更多信息 "PKIX path building failed" and "unable to find valid certification path to requested target"

对于网络,请尝试在您的浏览器上访问 URL 并检查它是否可用。如果您真的无法从您的浏览器使用 HTTPS 访问 Maven Central Repo,可能是因为您落后于某些代理规则,阻止您下载服务器证书。

您可以设置 settings.xml 文件如下:

 <proxies>
     <proxy>
         <active>true</active>
         <protocol>https</protocol>
         <host>MY_COMPANY_HOST</host>
         <port>8080</port>
         <username>MY_USERNAME</username>
         <password>MY_PASSWORD</password>
         <nonProxyHosts>localhost</nonProxyHosts>
     </proxy>
     <proxy>
         <active>true</active>
         <protocol>http</protocol>
         <host>MY_COMPANY_HOST</host>
         <port>8080</port>
         <username>MY_USERNAME</username>
         <password>MY_PASSWORD</password>
         <nonProxyHosts>localhost</nonProxyHosts>
     </proxy>
 </proxies>

并查看线程 Problems using Maven and SSL behind proxy 了解更多详细信息。