Downloading https://services.gradle.org/distributions/gradle-2.12-bin.zip
Exception in thread "main" javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
与此类似的问题:
gradlew.bat (and gradlew) SSLHandShakeException
除了我在通过包装器执行时只获得此异常? (已安装的本地gradle命令没有任何问题。)我尝试了建议的解决方案,但无法让它工作。我甚至从https://services.gradle.org/distributions/下载并安装了cacerts中的证书
keytool -import -file "C:\tmp\gradlew.x509.base64.cer" -alias gradle -keystore "C:\Apps\java\jre\lib\security\cacerts"
我从包装器中获取了命令:
java -Dorg.gradle.appname=gradlew -classpath "C:\mystuff\gradle-2.12\samples\java\multiproject\\gradle\wrapper\gradle-wrapper.jar" org.gradle.wrapper.GradleWrapperMain clean
我的猜测可能是证书本身有问题,或者我使用错误的编码?
$ java -version
Picked up _JAVA_OPTIONS: -Xmx512M
java version "1.7.0_25"
Java(TM) SE Runtime Environment (build 1.7.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)
为了使这一点复杂化,我尝试使用此处建议的方法从gradle安装证书,这似乎有效(根据输出)
http://infposs.blogspot.ca/2013/06/installcert-and-java-7.html
但是当我运行包装器时,我仍然会遇到同样的错误。
答案 0 :(得分:0)
我对SSL证书了解不多,但我注意到当我尝试为上面的url安装cert时,实际上会返回2个证书...仔细看看InstallCert.java中的java代码我注意到了它只安装(天真地?)第一个证书。
我更改了InstallCert.java中的代码(添加了for循环)和viola,安装了证书,gradle和java很乐意交换握手,所有人都过着幸福的生活。
这是我改变的代码
for (int i = 0; i < chain.length; i++) {
final X509Certificate cert = chain[i];
final String alias = host + "-" + (i + 1);
ks.setCertificateEntry(alias, cert);
final OutputStream out = new FileOutputStream(file);
ks.store(out, passphrase);
out.close();
System.out.println();
System.out.println(cert);
System.out.println();
System.out.println(
"Added certificate to keystore 'cacerts' using alias '"
+ alias + "'");
}
它位于main函数的末尾,其中调用了实际的keystore方法。
因此,如果您对InstallCert.java进行上述修改,解决方案非常简单:
javac InstallCert.java
java InstallCert services.gradle.org
顺便说一句,导致我调查这条道路的方式是当我针对较旧版本的java(我认为是1.6)运行客户端时,它会吐出以下错误:
java.security.cert.CertPathValidatorException: The certificate issued by ... is not trusted; internal cause is:
java.security.cert.CertPathValidatorException: Certificate chaining error