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

Github Actions中sbt-scalafmt插件下载scalafmt-core失败求助

解决scalafmtCheck在GitHub Actions中下载core失败的问题

问题背景

运行scalafmtCheck时,sbt插件尝试动态下载scalafmt core v3.7.1失败,报错无法找到该版本。本地运行正常,但GitHub Actions环境下即使清除缓存仍失败。配置情况:

  • scalafmt sbt插件版本:2.4.6
  • .scalafmt.conf中指定版本:3.7.1
  • GitHub Actions使用ubuntu-latest环境,配置了coursier缓存和setup-scala

报错信息:

[error] org.scalafmt.sbt.ScalafmtSbtReporter$ScalafmtSbtError: scalafmt: [v3.7.1] failed to download [/home/runner/work/pariplay-gateway/pariplay-gateway/.scalafmt.conf]
[error] (Compile / scalafmtCheck) org.scalafmt.sbt.ScalafmtSbtReporter$ScalafmtSbtError: scalafmt: [v3.7.1] failed to download [/home/runner/work/pariplay-gateway/pariplay-gateway/.scalafmt.conf]

解决方案

1. 验证版本兼容性

scalafmt sbt插件与core版本存在对应支持关系,插件2.4.6对core 3.7.1的支持可能存在兼容性问题。可尝试两种调整:

  • 升级sbt插件版本到2.5.0或更高(确认兼容core 3.7.1),修改project/plugins.sbt:
    addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.0")
    
  • 降低core版本到插件2.4.6明确支持的范围(如3.6.1),修改.scalafmt.conf中的version = 3.6.1

2. 显式在sbt配置中指定core版本

仅在.scalafmt.conf指定版本可能在CI环境中不生效,在build.sbt中全局锁定版本:

ThisBuild / scalafmtVersion := "3.7.1"

3. 确认CI环境中的配置文件完整性

检查.scalafmt.conf是否被正确拉取到CI环境,在Check formatting步骤前添加验证:

- name: Verify scalafmt config
  run: cat .scalafmt.conf

4. 排查依赖下载细节

在sbt命令中添加调试日志,查看具体下载失败的原因(如网络超时、artifact不存在):

- name: Check formatting 🔍
  run: sbt -debug ";scalafix --check; scalafmtCheck"

若为网络问题,可尝试在CI环境中配置maven镜像源或代理。

5. 临时禁用缓存测试

暂时关闭coursier缓存,确认是否缓存导致依赖拉取异常:

- name: Check formatting 🔍
  run: sbt --no-cache ";scalafix --check; scalafmtCheck"

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.30 17:11:14