How to resolve SSLHandshakeException

When ever I try to build my Gradle project i am getting SSLHandshakeException. I have tried with many Gradle builds/versions. I have also added the certificate to cacerts

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

This error indicates the certificate presented by the server is not trusted. It is possible some other entity is responding to you instead of services.gradle.com. When I use a web browser to open https://services.gradle.org, I can see a valid certificate. You should try the same.

This could happen if you are connected to some public wifi that intercepts all traffic until you login or accept some user agreement.