重复获得 "PKIX path building failed" 和 "unable to find valid certification path to requested target"

Repeatedly getting "PKIX path building failed" and "unable to find valid certification path to requested target"

我在 mvn clean install 执行期间一直面临证书这个烦人的问题。

PS C:\Users\milan\service> mvn clean install
[INFO] Scanning for projects...
Downloading from spring-milestones: https://repo.spring.io/milestone/org/springframework/boot/spring-boot-starter-parent/2.2.0.M6/spring-boot-starter-parent-2.2.0.M6.pom
Downloading from central: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starter-parent/2.2.0.M6/spring-boot-starter-parent-2.2.0.M6.pom
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[FATAL] Non-resolvable parent POM for com.demo.microservices:service:0.0.1-SNAPSHOT: Could not transfer artifact org.springframework.boot:spring-boot-starter-parent:pom:2.2.0.M6 from/to spring-milestones (https://repo.spring.io/milestone): transfer failed for https://repo.spring.io/milestone/org/springframework/boot/spring-boot-starter-parent/2.2.0.M6/spring-boot-starter-parent-2.2.0.M6.pom and 'parent.relativePath' points at no local POM @ line 4, column 11
 @
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]
[ERROR]   The project com.demo.microservices:service:0.0.1-SNAPSHOT (C:\Users\milan\service\pom.xml) has 1 error
[ERROR]     Non-resolvable parent POM for com.demo.microservices:service:0.0.1-SNAPSHOT: Could not transfer artifact org.springframework.boot:spring-boot-starter-parent:pom:2.2.0.M6 from/to spring-milestones (https://repo.spring.io/milestone): transfer failed for https://repo.spring.io/milestone/org/springframework/boot/spring-boot-starter-parent/2.2.0.M6/spring-boot-starter-parent-2.2.0.M6.pom and 'parent.relativePath' points at no local POM @ line 4, column 11: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target -> [Help 2]
[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/ProjectBuildingException
[ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/UnresolvableModelException

我发现 solution 工作正常。

有什么办法可以一劳永逸地解决这个问题吗?

系统:

Apache Maven 3.8.4 
Maven home: C:\apache-maven-3.8.4
Java version: 17.0.1, vendor: Eclipse Adoptium, runtime: C:\Program Files\Eclipse Adoptium\jdk-17.0.1.12-hotspot
Default locale: en_IN, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"

我可以通过替换 cacert 文件来解决这个问题。更准确地说,我已将 Eclipse Adoptium\jdk-17.0.1.12-hotspotcacert 替换为 Eclipse Adoptium\jre-8.0.312.7-hotspot 来修复它。

令我惊讶的是,替换新的 cacaert 文件后,我不必使用 keytool 手动加载证书。旧的 cacert 文件导致问题的原因仍然是个谜。

注意:在替换新文件之前备份原始 cacert 文件。

如果仍未解决,请尝试此 solution