Gangmax Blog

自由之思想,独立之精神

Gradle JDK Mismatching Issue in IntelliJ IDEA

I have a Gradle project written in Java. When I build it from command line, it works. But when running the test cases in IntelliJ IDEA, I get the following error:

Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
    at java.base/sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:385)
    at java.base/sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:290)
    at java.base/sun.security.validator.Validator.validate(Validator.java:264)
    at java.base/sun.security.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:321)
    at java.base/sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:221)
    at java.base/sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:129)
    at java.base/sun.security.ssl.CertificateMessage$T12CertificateConsumer.checkServerCerts(CertificateMessage.java:626)
    ... 286 more
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
    at java.base/sun.security.provider.certpath.SunCertPathBuilder.build(SunCertPathBuilder.java:141)
    at java.base/sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:126)
    at java.base/java.security.cert.CertPathBuilder.build(CertPathBuilder.java:297)
    at java.base/sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:380)
    ... 292 more

Since it works in command line, I’m pretty sure it’s caused by some configuration in IDEA.

The solution is here.

When I go to “Preferences -> Build, Execution, Deployment -> Gradle”, I find the JDK used in the “Gradle JVM” field is NOT the one I’m using in the command line(yes, I installed multiple JDKs on my computer). Change it to the same one as the command line and run the unit test again, it works now.

Another field “Use Gradle from” in the same UI is used to set the Gradle version for the current project, which is also important when you project needs specific version of Gradle to build.

Comments