Gradle cannot trust the HTTPS certificate of a repository (PKIX path building failed)
Cause: unable to find valid certification path to requested targetShort 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.
Fix it fast
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 --version2Match what you see, then jump to its fix
What does the error look like?
Cause: unable to find valid certification path to requested targetPKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested targetCould 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 changeit3Verify
List the entry, then run the build again.
keytool -list -cacerts -alias corp-root
./gradlew build --refresh-dependenciesConfirmed by docs.oracle.com
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 --version2Fix
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 changeit3Verify
Build once from the IDE and once from the terminal.
./gradlew helpConfirmed by developer.android.com
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
Gradle fails to resolve the buildscript classpath, so the build never starts
Could not find com.android.tools.build:gradle:8.x.x.
Gradle could not download a build plugin, usually the Android Gradle plugin.
3 causes, each with a fixMobile apps
adb cannot start because something already holds its port
adb start-server failed
The adb server must bind local TCP port 5037, and every adb client talks to it there.
2 causes, each with a fixMobile apps
The phone shows as unauthorized and Android Studio will not run the app
adb devices lists the phone but Android Studio cannot deploy to it
An unauthorized phone means it has not trusted this computer's RSA key.
3 causes, each with a fixMobile 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 fixMobile apps
adb cannot connect to its daemon or start the server
* daemon started successfully *
The adb server is a background process on your computer that listens on TCP port 5037.
2 causes, each with a fixMobile apps
adb prints 'server version doesn't match this client; killing...'
adb server version doesn't match this client; killing...
adb runs a background server, and every adb command is a client.
3 causes, each with a fix