Fix Java, Maven, Gradle, IntelliJ & Android Studio 'PKIX path building failed' on Mac

Fix PKIX path building failed: unable to find valid certification path to requested target in Java, Maven, Gradle, IntelliJ IDEA, and Android Studio behind Zscaler, Cloudflare WARP, or Netskope on macOS.

SWG bar · Updated

On a corporate MacBook behind an SSL-inspecting Secure Web Gateway (Zscaler, Cloudflare WARP, Netskope, Cisco Umbrella, Palo Alto, or Fortinet), Java, Maven, Gradle, IntelliJ IDEA, Android Studio, and Eclipse routinely fail dependency downloads and SDK syncs with:

javax.net.ssl.SSLHandshakeException: PKIX path building failed:
sun.security.provider.certpath.SunCertPathBuilderException:
unable to find valid certification path to requested target

This happens because the JVM reads its own isolated cacerts truststore instead of macOS System Keychain—and a typical developer Mac has three to five separate JVMs (Homebrew OpenJDK, SDKMAN/Temurin, IntelliJ’s bundled JetBrains Runtime, and Android Studio’s bundled JBR). Paste your raw stack trace into our free SWG & SSL Error Decoder or follow the exact macOS fixes below.

1. Export your corporate SWG Root CA PEM on macOS

First verify which gateway is re-signing traffic to repo.maven.apache.org or services.gradle.org via SWG bar → Certificates or Terminal:

openssl s_client -connect repo.maven.apache.org:443 -servername repo.maven.apache.org </dev/null 2>/dev/null | openssl x509 -noout -issuer

Then export the matching root certificate from macOS System Keychain into ~/.certs/corporate-swg-root.pem:

mkdir -p "$HOME/.certs"
# Replace "Zscaler" with Cloudflare, goskope, Cisco Umbrella, Fortinet, or your corporate CA name
security find-certificate -c "Zscaler" -p /Library/Keychains/System.keychain > "$HOME/.certs/corporate-swg-root.pem"

2. Fastest fix: make Java, Maven & Gradle read macOS Keychain directly

On macOS, modern OpenJDK builds include Apple’s KeychainStore provider, which lets the JVM trust your MDM-installed SWG root CA without manually modifying cacerts:

  • Gradle (persistent for all projects) — add to ~/.gradle/gradle.properties:
    systemProp.javax.net.ssl.trustStoreType=KeychainStore
    Then stop any running daemon so Gradle reloads TLS settings:
    ./gradlew --stop
  • Maven — add to ~/.zshrc:
    export MAVEN_OPTS="-Djavax.net.ssl.trustStoreType=KeychainStore"
  • Standalone Java CLI:
    java -Djavax.net.ssl.trustStoreType=KeychainStore -jar app.jar

(Note: Some third-party JDK builds or Gradle plugins explicitly open cacerts or ignore KeychainStore. If you still see PKIX path building failed, import the root CA into each active cacerts store below.)

3. Import the SWG Root CA into cacerts (JDK, IntelliJ & Android Studio)

Check which JDK is active in your shell (echo "$JAVA_HOME"), then import the PEM using keytool (default cacerts password is changeit):

# Active JAVA_HOME (JDK 9+)
sudo "$JAVA_HOME/bin/keytool" -importcert -cacerts \
  -storepass changeit -noprompt \
  -alias corporate-swg-root \
  -file "$HOME/.certs/corporate-swg-root.pem"

Critical macOS cacerts paths that developers miss

Fixing only $JAVA_HOME often leaves IDE syncs broken because JetBrains IDEs and Android Studio run on their own bundled JetBrains Runtime (jbr)—and Android Studio 2024+ renamed jre to jbr:

Tool on macOS Default cacerts path Command / Note
Homebrew OpenJDK (Apple Silicon) /opt/homebrew/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/security/cacerts Re-run after brew upgrade openjdk
Android Studio (2024+) /Applications/Android Studio.app/Contents/jbr/Contents/Home/lib/security/cacerts Older versions used Contents/jre/...
IntelliJ IDEA /Applications/IntelliJ IDEA.app/Contents/jbr/Contents/Home/lib/security/cacerts Also check Settings → Tools → Server Certificates and add ~/.certs/corporate-swg-root.pem
SDKMAN / Downloaded JDKs ~/.sdkman/candidates/java/current/lib/security/cacerts or ~/Library/Java/JavaVirtualMachines/*/Contents/Home/lib/security/cacerts Check Project SDK in File → Project Structure → SDKs
Eclipse Bundled JustJ JRE inside /Applications/Eclipse.app/Contents/Eclipse/plugins/.../lib/security/cacerts Or point eclipse.ini -vm to your configured JDK

Example command for Android Studio on macOS:

sudo "/Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/keytool" \
  -importcert -noprompt -storepass changeit \
  -keystore "/Applications/Android Studio.app/Contents/jbr/Contents/Home/lib/security/cacerts" \
  -alias corporate-swg-root \
  -file "$HOME/.certs/corporate-swg-root.pem"

Verify the import and restart the IDE + Gradle daemons:

"$JAVA_HOME/bin/keytool" -list -cacerts -storepass changeit -alias corporate-swg-root
./gradlew --stop

4. Why cacerts breaks again after updates—and how to bypass per domain

Every macOS Android Studio update, IntelliJ Toolbox upgrade, or brew upgrade openjdk replaces the bundled cacerts file and wipes out your custom keytool import.

If your company policy permits per-domain SWG bypass for developer registries, SWG bar detects exactly which artifact hosts (repo.maven.apache.org, services.gradle.org, plugins.gradle.org, dl.google.com) are being decrypted and lets you bypass them per domain in one click—without touching a single cacerts file or lowering TLS security:

swgbar probe repo.maven.apache.org
swgbar bypass enable repo.maven.apache.org
swgbar bypass enable services.gradle.org
swgbar bypass enable dl.google.com

Need to fix other macOS developer tools too? See How to bypass SWG on a Mac, Fix Git & npm SSL certificate errors, and Fix Python & Docker SSL errors on Mac.