You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Sbt升级报错:java.lang.ClassNotFoundException: okhttp3.Interceptor

解决sbt升级至1.8.3/1.9.3时的okhttp3.Interceptor找不到问题

问题根源

sbt 1.9.x官方已移除okhttp依赖,但当前环境残留了旧版本zinc-classpath(2.12-1.6.0),它仍在引用okhttp3.Interceptor,同时旧缓存里的okhttp-3.14.2.jar未清理干净,导致版本冲突引发ClassNotFoundException。

具体解决步骤

  • 清理本地sbt缓存
    彻底删除sbt和ivy的缓存目录,清除旧依赖残留:

    # Linux/macOS
    rm -rf ~/.sbt ~/.ivy2/cache
    # Windows 手动删除以下目录
    # C:\Users\<你的用户名>\.sbt
    # C:\Users\<你的用户名>\.ivy2\cache
    
  • 重置IntelliJ的sbt相关缓存

    1. 打开IntelliJ,选择File > Invalidate Caches...
    2. 勾选「Clear file system cache and local history」,点击「Invalidate and Restart」
    3. 重启后在sbt工具窗口点击刷新按钮,重新加载项目依赖
  • 确认项目sbt版本配置
    检查项目根目录下的project/build.properties,确保内容为:

    sbt.version=1.9.3
    

    同时排查全局sbt配置(~/.sbt/1.0/global.sbt)或项目内的global.sbt,删除任何强制引入okhttp或指定旧版zinc的配置代码

  • 修复GitLab CI/CD的缓存问题
    在.gitlab-ci.yml中调整缓存策略,避免复用旧版本缓存:

    cache:
      key: sbt-$CI_COMMIT_REF_NAME-1.9.3
      paths:
        - ~/.sbt
        - ~/.ivy2/cache
    

    也可以在before_script阶段添加清理命令,确保每次流水线都用干净的依赖:

    before_script:
      - rm -rf ~/.sbt ~/.ivy2/cache
      - sbt --version
    
  • 排查并排除多余依赖
    安装sbt-dependency-tree插件(在project/plugins.sbt中添加):

    addSbtPlugin("net.virtual-void" % "sbt-dependency-tree" % "0.10.0-RC1")
    

    执行sbt dependencyTree查看依赖树,找到引入okhttp3的依赖,通过exclude排除:

    libraryDependencies += "你的依赖组" % "依赖名" % "版本" exclude("com.squareup.okhttp3", "okhttp")
    

内容的提问来源于stack exchange,提问作者vasigorc

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.14 16:15:16