Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Flutter and app store releases

Gradle cannot trust the HTTPS certificate of a repository (PKIX path building failed)

ErrorCause: unable to find valid certification path to requested target

Short answer

The JDK that runs Gradle does not trust the certificate chain it received. This usually means a company proxy re-signs HTTPS traffic with its own root certificate. Import that root into the cacerts store of the same JDK Gradle runs on. Disabling certificate checks is not a fix.

  • Applies to Gradle 8.x and 9.x, JDK 17 and 21, Android Studio current stable
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Find out which JDK runs Gradle, because that JDK's own certificate store is the one that matters.

    ./gradlew --version
  2. 2Match what you see, then jump to its fix

    1. 1The error appears for every repository on a work network and goes away on a home connectionA proxy or firewall re-signs HTTPS with a private root certificateFix
    2. 2keytool lists the certificate, yet Gradle still failsThe certificate went into a different JDK than the one Gradle usesFix

What does the error look like?

  • Cause: unable to find valid certification path to requested target
  • PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
  • Could not GET 'https://repo.maven.apache.org/maven2/...'

Cause 1 of 2

A proxy or firewall re-signs HTTPS with a private root certificate

1Check

Print the chain the network presents. If the top issuer is your company or a security product and not a public authority, the JDK has never heard of it.

openssl s_client -showcerts -connect repo.maven.apache.org:443 </dev/null | grep -E 'issuer|subject'

2Fix

Get the root certificate file from your IT team and import it into the cacerts store of the Gradle JDK, using that JDK's own keytool. The default store password is changeit unless your admin changed it.

keytool -importcert -alias corp-root -file corp-root.cer -cacerts -storepass changeit

3Verify

List the entry, then run the build again.

keytool -list -cacerts -alias corp-root
./gradlew build --refresh-dependencies

Confirmed by docs.oracle.com

Did this fix it?

Cause 2 of 2

The certificate went into a different JDK than the one Gradle uses

1Check

Android Studio runs Gradle with the JDK chosen in its Gradle settings. A terminal build uses JAVA_HOME, or java on the PATH. Two JDKs means two separate certificate stores.

echo $JAVA_HOME
./gradlew --version

2Fix

Run keytool from the JDK that Gradle reports, and set the IDE and JAVA_HOME to that same JDK so every build uses it.

"$JAVA_HOME/bin/keytool" -importcert -alias corp-root -file corp-root.cer -cacerts -storepass changeit

3Verify

Build once from the IDE and once from the terminal.

./gradlew help

Confirmed by developer.android.com

Did this fix it?

How do I stop it coming back?

  • Keep one JDK for the IDE and the terminal, and import the corporate root once into it.
  • Re-import the certificate after a JDK upgrade, because a new JDK starts with a fresh store.
  • Never switch certificate validation off to get a build through.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Mobile apps

Android Studio cannot pair the phone over Wi-Fi

The Pair devices over Wi-Fi dialog lists no device

Wireless pairing needs the phone on Android 11 or higher and on the same Wi-Fi network as the computer, with current Platform-Tools.

4 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.