IntelliJ打开SBT项目失败:jansi 1.11依赖无法解析及证书错误
Hey there, let's tackle this SBT import issue you're facing head-on. From the error logs you shared, the core problems are two-fold: your setup can't fetch the jansi 1.11 dependency, and the real root cause is a PKIX certificate validation failure when trying to connect to HTTPS repositories like Maven Central. Here's how to fix this step by step:
1. Resolve the PKIX Certificate Trust Issue (Root Cause)
The "PKIX path building failed" error means your JVM doesn't trust the SSL certificates of the repositories you're trying to access. You have two solid options here:
Option A: Manually Import Repository Certificates (Recommended for Long-Term)
- Open your browser and navigate to the main Maven Central repository site. Click the lock icon in the address bar, go to certificate details, and export the certificate as a DER-formatted file.
- Locate the
cacertsfile in your JDK's security directory (typicallyC:\Program Files\Java\jdk[your-version]\jre\lib\security\cacerts). - Launch Command Prompt as Administrator and run this command to import the certificate:
keytool -import -alias maven-central -keystore "C:\Program Files\Java\jdk[your-version]\jre\lib\security\cacerts" -file "C:\path\to\your\exported\certificate.cer"- The default password for the
cacertsstore ischangeit.
- The default password for the
Option B: Temporarily Skip SSL Validation (For Debugging Only)
If you need a quick fix to test things out, add VM parameters to your SBT configuration in IntelliJ:
- Go to
File > Settings > Build, Execution, Deployment > Build Tools > sbt - In the VM parameters field, add:
Important: This disables SSL security checks, so avoid using this in production environments.-Dssl.trustAll=true
2. Adjust SBT Dependencies & Repository Config
Update to a Newer Jansi Version
The 1.11 version of Jansi is quite outdated, and some repositories might no longer host it. Try explicitly declaring a newer, compatible version in your build.sbt:
libraryDependencies += "org.fusesource.jansi" % "jansi" % "1.18"
Verify Repository Setup
Make sure your build.sbt includes Maven Central as a resolver:
resolvers += "Maven Central" at "https://repo1.maven.org/maven2/"
3. Clean Local Caches & Restart
Corrupted local cache files can often cause dependency issues. Let's clear them and retry:
- Delete the following directories:
C:\Users\user_name\.ivy2\localC:\Users\user_name\.sbt\preloaded
- In IntelliJ, go to
File > Invalidate Caches... > Invalidate and Restart - After the IDE restarts, re-import your SBT project.
After following these steps, your SBT project should import successfully without the Jansi dependency error.
内容的提问来源于stack exchange,提问作者Foxlooo

