mvn命令报错:unable to find valid certification path to requested target

问题

mvn仓库地址变更之后,mvn 命令报错,无法下载jar包

  • 报错
[*ERROR*] Plugin org.apache.maven.plugins:maven-enforcer-plugin:1.2 
or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-enforcer-plugin:jar:1.2: 
Could not transfer artifact org.apache.maven.plugins:maven-enforcer-plugin:pom:1.2 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 -> *[Help 1]*

解决

  • 导入mvn仓库网址的https相关证书到本地JDK
  • 关闭抓包工具

原因

  • mvn客户端连接服务端出现问题
    仓库地址由http转到了https,https连接会校验证书;而Charles(抓包工具)为了抓取https包,修改了https证书,签发者变了;mvn 客户端不信任修改后的https证书,拒绝建立连接
  1. 正常aliyun.com的CA证书


    image.png
  2. 抓包工具Charles打开之后的证书


    image.png

扩展

  • 其他java报出的unable to find valid certification path to requested target,基本也都是这个原因,可以了解一下 https双向认证

参考

彻底解决unable to find valid certification path to requested target

你可能感兴趣的:(mvn命令报错:unable to find valid certification path to requested target)