Open https://repo.maven.apache.org or https://dl.google.com in Chrome on a corporate MacBook and everything loads cleanly. Switch to Terminal or Android Studio, run ./gradlew build or mvn clean test, and your build immediately aborts:
javax.net.ssl.SSLHandshakeException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target Behind a TLS-inspecting Secure Web Gateway (SWG)—such as Zscaler, Cloudflare WARP / Zero Trust, Netskope, Cisco Umbrella, Palo Alto GlobalProtect, or Fortinet FortiClient—this is one of the most persistent macOS developer headaches.
The mechanics are simple, yet macOS introduces a multi-JVM trap that catches even senior engineers:
- Corporate SWGs re-sign HTTPS connections with an internal root CA pushed to macOS System Keychain via MDM. Safari and Chrome trust System Keychain automatically.
- The JVM ignores macOS Keychain by default. Every Java runtime validates certificates against its own isolated
lib/security/cacertsfile. - A developer Mac rarely has just one JVM. Between Homebrew OpenJDK, SDKMAN/Temurin, IntelliJ IDEA's bundled JetBrains Runtime (
jbr), and Android Studio's bundledjbr, you easily end up with four or five separatecacertsstores—plus long-lived Gradle daemons caching stale TLS contexts in memory.
If you are untangling SSL stack traces across multiple toolchains at once, paste the raw error into the free SWG & SSL Error Decoder to identify the exact runtime and trust store. Below is the upgrade-safe macOS playbook for Java, Maven, Gradle, IntelliJ IDEA, and Android Studio—without weakening TLS security.
Step 1: Identify the Inspecting Root CA & Active JVMs
Before modifying any truststore, confirm which CA is signing handshakes to your artifact registries (repo.maven.apache.org, services.gradle.org, plugins.gradle.org, or dl.google.com) and list every JDK registered on macOS:
# Inspect the live TLS issuer for Maven Central openssl s_client -connect repo.maven.apache.org:443 \ -servername repo.maven.apache.org </dev/null 2>/dev/null \ | openssl x509 -noout -issuer -subject -dates # List all registered macOS JDKs /usr/libexec/java_home -V If the issuer line shows your corporate gateway (Zscaler, Cloudflare, Netskope, Cisco Umbrella, Fortinet, or an internal enterprise CA) rather than a public CA like DigiCert or Google Trust Services, HTTPS inspection is active on that domain. You can also verify your Mac's TLS interception behavior using the Work Mac SSL Check tool.
Export the matching root certificate from macOS System Keychain and verify that the PEM file is valid before importing it:
mkdir -p "$HOME/.certs" # Replace "Zscaler" with Cloudflare, goskope, Umbrella, Fortinet, or your corporate CA name security find-certificate -c "Zscaler" -p \ /Library/Keychains/System.keychain > "$HOME/.certs/corporate-swg-root.pem" # Confirm the exported PEM is non-empty and matches your corporate CA openssl x509 -in "$HOME/.certs/corporate-swg-root.pem" -noout -subject -issuer -dates Step 2: Start with the Upgrade-Safe Fix (KeychainStore)
Before patching cacerts across multiple JDK folders, try Apple's built-in KeychainStore provider included in modern macOS OpenJDK builds. It makes the JVM trust certificates directly from macOS Keychain, so MDM root rotations and brew upgrade openjdk updates keep working without manual re-imports.
Gradle (persistent across projects)
Add this line to ~/.gradle/gradle.properties:
systemProp.javax.net.ssl.trustStoreType=KeychainStore Then stop all running Gradle daemons. Forgetting this step is the #1 reason a working fix looks broken—running daemons hold onto their previous SSLContext:
./gradlew --stop Maven
Add MAVEN_OPTS to ~/.zshrc (then run source ~/.zshrc):
export MAVEN_OPTS="-Djavax.net.ssl.trustStoreType=KeychainStore" Standalone Java CLI
java -Djavax.net.ssl.trustStoreType=KeychainStore -jar app.jar Caveat: Some third-party JDK distributions, older Gradle wrappers, or custom Maven plugins open $JAVA_HOME/lib/security/cacerts explicitly and ignore KeychainStore. If SunCertPathBuilderException persists, proceed to Step 3.
Step 3: Import the Root CA into cacerts (JDK, IntelliJ IDEA & Android Studio)
Fixing only your shell $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 Contents/jre to Contents/jbr.
Check these macOS cacerts paths:
| Tool on macOS | Default cacerts Path | Notes |
|---|---|---|
| Homebrew OpenJDK (Apple Silicon) | /opt/homebrew/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/security/cacerts | Replaced on brew upgrade openjdk |
| Android Studio (2024+) | /Applications/Android Studio.app/Contents/jbr/Contents/Home/lib/security/cacerts | Older builds used Contents/jre/... |
| IntelliJ IDEA | /Applications/IntelliJ IDEA.app/Contents/jbr/Contents/Home/lib/security/cacerts | Also add the PEM in Settings → Tools → Server Certificates; Toolbox installs under ~/Applications/ |
| SDKMAN / Temurin / Corretto | ~/.sdkman/candidates/java/current/lib/security/cacerts or ~/Library/Java/JavaVirtualMachines/*/Contents/Home/lib/security/cacerts | Verify active SDK in Project Structure → SDKs and Gradle JVM |
| Eclipse | Bundled JustJ JRE under /Applications/Eclipse.app/Contents/Eclipse/plugins/.../lib/security/cacerts | Or point -vm in eclipse.ini to your configured JDK |
Import your exported PEM with keytool (default password is changeit):
# Active shell 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" # Android Studio bundled JetBrains Runtime (2024+) 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 Gradle daemons + IDE "$JAVA_HOME/bin/keytool" -list -cacerts -storepass changeit -alias corporate-swg-root ./gradlew --stop Surviving JDK Updates with a User-Owned Copy
If KeychainStore does not cover a plugin and you are tired of re-running keytool after every JDK update, copy a clean cacerts to ~/.certs/jvm-cacerts, import corporate-swg-root.pem there once, and point Gradle to it:
# ~/.gradle/gradle.properties systemProp.javax.net.ssl.trustStore=/Users/<your-username>/.certs/jvm-cacerts systemProp.javax.net.ssl.trustStorePassword=changeit Keep in mind the trade-off: unlike KeychainStore, a copied truststore will not receive upstream public CA updates automatically, so refresh the base copy periodically. For a compact reference covering every macOS JDK and IDE path, bookmark the Java, Maven, Gradle, IntelliJ & Android Studio PKIX guide.
Step 4: Why Manual Trust Stores Still Break
Even after builds turn green, three edge cases routinely bring PKIX path building failed back:
- Silent toolchain updates: Running
brew upgrade openjdk, switching JDKs withsdk use java, or installing an Android Studio / JetBrains Toolbox update replaceslib/security/cacertswith a stock file, wiping customkeytoolentries. - Mismatched Gradle JVM: Your shell uses OpenJDK 21 while IntelliJ's Settings → Build, Execution, Deployment → Build Tools → Gradle → Gradle JVM runs a separate bundled JBR whose truststore was never updated.
- Certificate pinning and mutual TLS (mTLS): Updating
KeychainStoreorcacertsonly resolves standard CA-chain trust. If an SDK updater, internal API client, or plugin enforces SPKI certificate pinning or mutual TLS (mTLS), SWG re-signing will always abort the handshake. Read why certificate-pinned apps and mTLS break under SWG inspection for the exact breakdown.
Security & Acceptable-Use Boundaries: Skip Unsafe Shortcuts
Under deadline pressure, it is tempting to copy quick workarounds from old forum threads. Avoid anything that disables TLS validation:
- Never add
-Dmaven.wagon.http.ssl.insecure=trueor-Dmaven.wagon.http.ssl.allowall=trueto Maven. - Never enable "Accept non-trusted certificates automatically" in IntelliJ IDEA or Android Studio.
- Never drop a trust-all
X509TrustManagerinto build scripts or test code.
Turning off verification leaves dependency downloads open to silent tampering on untrusted Wi-Fi—and those flags frequently leak into shared repos and CI.
Stay within your organization's security and acceptable-use policies:
- Managed enterprise Macs: Keep SWG inspection intact and configure CA trust cleanly via
KeychainStoreorcacerts. For pinned or mTLS hosts that CA trust cannot fix, ask IT for a targeted SSL Inspection Bypass / Do-Not-Decrypt rule for specific developer domains (repo.maven.apache.org,services.gradle.org,dl.google.com). - Authorized local diagnostics & selective routing: On networks where your organization permits per-domain routing over a physical IPv4 interface without disabling the SWG agent or breaking SSO posture, see how per-domain SWG bypass on macOS isolates specific artifact hosts while keeping full TLS validation enforced.
