Maven:无法读取构件描述符错误

huangapple go评论79阅读模式
英文:

Maven: Failed to read artifact descriptor error

问题

我克隆了一个Java代码库,当我尝试用"mvn install"构建时,我遇到了以下错误:

无法传输 artifact org.springframework.boot:spring-boot-starter-parent:pom:2.3.2.RELEASE 从 central (https://repo.maven.apache.org/maven2):传输失败,来自 https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starter-parent/2.3.2.RELEASE/spring-boot-starter-parent-2.3.2.RELEASE.pom 的 'parent.relativePath' 指向没有本地 POM,在第 6 行,第 13 列:PKIX path 建立失败:sun.security.provider.certpath.SunCertPathBuilderException: 无法找到到请求目标的有效认证路径 -> [帮助 2]

在我的浏览器中打开"https://repo.maven.apache.org/maven2",该仓库是可访问的。

经过一些搜索,我在".m2"文件夹中放了一个名为settings.xml的文件,内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<settings>
  <activeProfiles>
    <!-- 使配置始终处于活动状态 -->
    <activeProfile>securecentral</activeProfile>
  </activeProfiles>
  <profiles>
    <profile>
      <id>securecentral</id>
      <!-- 覆盖来自 Maven Super POM 的仓库(和 pluginRepository)"central"部分 -->
	  <repositories>
        <repository>
          <id>central</id>
          <url>https://repo1.maven.org/maven2</url>
          <releases>
            <enabled>true</enabled>
          </releases>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <id>central</id>
          <url>https://repo1.maven.org/maven2</url>
          <releases>
            <enabled>true</enabled>
          </releases>
        </pluginRepository>
      </pluginRepositories>
    </profile>
  </profiles>
</settings>

现在当我运行"mvn install"时,spring-boot 的错误消失了。但是我现在面临这个错误:

无法读取 org.apache.camel.springboot:camel-salesforce-starter:jar:3.4.2 的 artifact 描述:无法传输 artifact io.dropwizard.metrics:metrics-bom:pom:4.1.9 从 central (https://repo.maven.apache.org/maven2):传输失败,来自 https://repo.maven.apache.org/maven2/io/dropwizard/metrics/metrics-bom/4.1.9/metrics-bom-4.1.9.pom 的 'parent.relativePath' 指向没有本地 POM,在第 6 行,第 13 列:PKIX path 建立失败:sun.security.provider.certpath.SunCertPathBuilderException: 无法找到到请求目标的有效认证路径 -&gt; [帮助 1]

我的问题是,为什么我需要在 settings.xml 中手动添加 ,以及为什么我仍然在camel的情况下收到错误?谢谢。

英文:

I cloned a JAVA repo and when I tried to build it with "mvn install", I got the following error

Could not transfer artifact org.springframework.boot:spring-boot-starter-parent:pom:2.3.2.RELEASE from/to central (https://repo.maven.apache.org/maven2): Transfer failed for https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starter-parent/2.3.2.RELEASE/spring-boot-starter-parent-2.3.2.RELEASE.pom and &#39;parent.relativePath&#39; points at no local POM @ line 6, column 13: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target -&gt; [Help 2]

the repo "https://repo.maven.apache.org/maven2" is accessible in my browser when I open it in Chrome.

After some googling, I put a settings.xml file in the .m2 folder looks like this

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;settings&gt;
  &lt;activeProfiles&gt;
    &lt;!--make the profile active all the time --&gt;
    &lt;activeProfile&gt;securecentral&lt;/activeProfile&gt;
  &lt;/activeProfiles&gt;
  &lt;profiles&gt;
    &lt;profile&gt;
      &lt;id&gt;securecentral&lt;/id&gt;
      &lt;!--Override the repository (and pluginRepository) &quot;central&quot; from the
         Maven Super POM --&gt;    
	  &lt;repositories&gt;
        &lt;repository&gt;
          &lt;id&gt;central&lt;/id&gt;
          &lt;url&gt;https://repo1.maven.org/maven2&lt;/url&gt;
          &lt;releases&gt;
            &lt;enabled&gt;true&lt;/enabled&gt;
          &lt;/releases&gt;
        &lt;/repository&gt;
      &lt;/repositories&gt;
      &lt;pluginRepositories&gt;
        &lt;pluginRepository&gt;
          &lt;id&gt;central&lt;/id&gt;
          &lt;url&gt;https://repo1.maven.org/maven2&lt;/url&gt;
          &lt;releases&gt;
            &lt;enabled&gt;true&lt;/enabled&gt;
          &lt;/releases&gt;
        &lt;/pluginRepository&gt;
      &lt;/pluginRepositories&gt;
    &lt;/profile&gt;
  &lt;/profiles&gt;
&lt;/settings&gt;

Now when I run "mvn install", the error for spring-boot goes away. But I am facing this error now:

Failed to read artifact descriptor for org.apache.camel.springboot:camel-salesforce-starter:jar:3.4.2: Could not transfer artifact io.dropwizard.metrics:metrics-bom:pom:4.1.9 from/to central (https://repo.maven.apache.org/maven2): Transfer failed for https://repo.maven.apache.org/maven2/io/dropwizard/metrics/metrics-bom/4.1.9/metrics-bom-4.1.9.pom: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target -&gt; [Help 1]

My question is, why do I need to manually add <repositories> and <pluginRepositories> in settings.xml and why I am still getting the error for camel? Thanks

答案1

得分: 1

你可以尝试运行 mvn -U clean install

-U 根据Maven命令行选项是用于

> 强制在远程仓库上检查丢失的发布版本和更新的快照版本

或者尝试删除本地仓库文件夹。有时在网络出现问题时会出现混乱... 你可以在.m2文件夹中找到本地仓库文件夹(在Windows上:C:\Users<你的用户名>.m2)

你可以删除整个仓库文件夹或部分内容。之后只需运行mvn clean install

英文:

You can try to run mvn -U clean install

-U according to Maven CLI options is for

> Forces a check for missing releases and updated snapshots on remote
> repositories

or try to delete the local repository folder. Sometimes it gets messed up when having network problems...
You can find your local repo folder in your .m2 folder (on windows: C:\Users&lt;your_username>.m2)

You can delete the whole repository folder or just some part of it. After that just run the mvn clean install

答案2

得分: 1

> PKIX路径构建失败:
> sun.security.provider.certpath.SunCertPathBuilderException:无法
> 找到到所请求目标的有效认证路径

几乎可以确定您系统上的根CA证书已过期。
尝试更新您的JDK安装。请注意,您的浏览器使用的CA证书可能与JRE/JDK使用的证书不同。

如果不了解您系统的更多细节,很难提供更准确的答案。

此回答 提供了可能的解决方法。

英文:

> PKIX path building failed:
> sun.security.provider.certpath.SunCertPathBuilderException: unable to
> find valid certification path to requested target

Almost certain that root CA certificates on your system are outdated.
Try to update your JDK installation. Note that CA certificate used by your browser might not be same as JRE/JDK is using.

Without knowing more details about your system, it's hard to provide more accurate answer.

This answer provides possible workaround.

答案3

得分: 0

OK...搞定了。

@rkosegi的答案让我找对了方向。我的浏览器使用的根CA证书与jdk使用的不同。这就是为什么我可以在浏览器中查看存储库而没有错误,但Maven无法访问该存储库的原因。

不知何故,我们公司(一个金融机构)有一个覆盖所有其他根CA证书的根CA证书,这意味着当我打开任何网站(例如stackoverflow)时,证书路径总是显示如下:

Maven:无法读取构件描述符错误

我不是系统管理员,也不知道是如何完成的,但无论如何,我所需做的就是将根CA证书保存为*.CER文件,并将其添加到jdk的cacert文件夹中。

之后,运行命令“mvn clean install”就能顺利完成,没有错误。

英文:

OK...got it working.

@rkosegi's answer put me on the right path. The root CA cert used by my browser is different than the one jdk uses. That's why I can view the repo in browser with no error but maven cannot access the repo.

Somehow my company (a financial institution) has a root CA cert overriding all the other root CA cert, that means, when I open any website (for example stackoverflow), the cert path always shows like this:

Maven:无法读取构件描述符错误

I am not a system admin and not sure how this is done, but anyhow, all I need to do is save the Root CA cert as a *.CER file and add it to the jdk's cacert folder.

After that, the command "mvn clean install" runs to complete with no error

huangapple
  • 本文由 发表于 2020年8月25日 01:33:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/63565970.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定