# Unable to build a Java project due to certificates

**URL:** <https://discuss.gradle.org/t/unable-to-build-a-java-project-due-to-certificates/46993>\
**Category:** Help/Discuss\
**Created:** [November 14, 2023, 10:19pm UTC](https://discuss.gradle.org/t/unable-to-build-a-java-project-due-to-certificates/46993 "2023-11-14T22:19:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![vmaier3000](https://avatars.discourse-cdn.com/v4/letter/v/ee59a6/32.png) [@vmaier3000](https://discuss.gradle.org/u/vmaier3000)\
**Post date:** [November 14, 2023, 10:19pm UTC](https://discuss.gradle.org/t/unable-to-build-a-java-project-due-to-certificates/46993/1 "2023-11-14T22:19:04Z")

</div>

I have been able to build Java project for years but recently I can no longer build anyone of them.  
(see below for the actual error)

My coworkers are able to build the same projects with the same files. So obviously I suspected the Java certificates. I got a file from one of my coworkers that can build the projects and copied them in 3 locations where different versions of Java are located but that did not help.  
Any ideas please?

And the error message:

```plaintext
C:\build\prod\Java\SampleProject>gradlew build -x test
Downloading https://services.gradle.org/distributions/gradle-6.3-bin.zip

Exception in thread "main" javax.net.ssl.SSLHandshakeException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
        at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:128)
        at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:321)
        at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:264)
        at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:259)
        at java.base/sun.security.ssl.CertificateMessage$T12CertificateConsumer.checkServerCerts(CertificateMessage.java:642)
        at java.base/sun.security.ssl.CertificateMessage$T12CertificateConsumer.onCertificate(CertificateMessage.java:461)

```

---

<div class="post-metadata">

**Author:** ![Vampire](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/vampire/32/9082_2.png) [@Vampire](https://discuss.gradle.org/u/Vampire)\
**Post date:** [November 15, 2023, 1:51pm UTC](https://discuss.gradle.org/t/unable-to-build-a-java-project-due-to-certificates/46993/2 "2023-11-15T13:51:52Z")

</div>

This most often happens when you use a JVM that is corrupt or has trusted certificates missing.  
You should try to build using a different / freshly installed JDK.

---

<div class="post-metadata">

**Author:** ![djKianoosh](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/djkianoosh/32/10669_2.png) [@djKianoosh](https://discuss.gradle.org/u/djKianoosh)\
**Post date:** [November 17, 2023, 4:45pm UTC](https://discuss.gradle.org/t/unable-to-build-a-java-project-due-to-certificates/46993/3 "2023-11-17T16:45:40Z")

</div>

If your company runs something like ZScaler, which intercepts SSL traffic and presents its own certificate, you may also run into this issue.

There’s a couple of approaches to solve this. One, add those CA certs to your Java cacerts. Or, if your sysadmins have already added those certs to your system’s root certificates, then you can tell gradle/java to trust the root certs. Gradle apparently does this from 8.3, but there is a workaround for earlier versions: [https://github.com/gradle/gradle/pull/25106](https://github.com/gradle/gradle/pull/25106)

I have this in my `~/.gradle/gradle.properties` on my mac:

```gradle
systemProp.javax.net.ssl.trustStore=/dev/null
systemProp.javax.net.ssl.trustStoreType=KeychainStore
systemProp.java.security.KeyStore=KeychainStore

```

Here’s the same thing for Windows:

```gradle
systemProp.javax.net.ssl.trustStore=NUL
systemProp.javax.net.ssl.trustStoreType=Windows-ROOT

```

---

<div class="post-metadata">

**Author:** ![vmaier3000](https://avatars.discourse-cdn.com/v4/letter/v/ee59a6/32.png) [@vmaier3000](https://discuss.gradle.org/u/vmaier3000)\
**Post date:** [November 21, 2023, 3:59am UTC](https://discuss.gradle.org/t/unable-to-build-a-java-project-due-to-certificates/46993/4 "2023-11-21T03:59:45Z")

</div>

Thank you for the suggestion, I will try to do that!
