sbt scalafmt "must be formatted" check failure in CI
The CI step ran scalafmtCheckAll (or scalafmtCheck), which fails if any file is not already formatted to the .scalafmt.conf rules. It does not rewrite files; it only reports the ones that differ.
What this error means
A formatting gate fails with "X.scala must be formatted" or "Some files are not formatted properly" and lists the offending files.
scalafmt
[error] /src/main/scala/App.scala isn't formatted properly!
[error] --- a/App.scala
[error] +++ b/App.scala (formatted)
[error] (Compile / scalafmtCheck) scalafmt: 1 files must be formattedCommon causes
Code was committed without running scalafmt
The file differs from the formatted output because it was not run through scalafmtAll before committing.
A scalafmt version or config mismatch
A different version in .scalafmt.conf locally versus CI produces different formatting, so the check flags files that look formatted locally.
How to fix it
Format the files and commit
- Run
sbt scalafmtAll(andscalafmtSbt) to rewrite files. - Commit the reformatted files.
- Re-run CI so
scalafmtCheckAllpasses.
Terminal
sbt scalafmtAll scalafmtSbtPin the scalafmt version in config
Set an explicit version in .scalafmt.conf so local and CI formatting are byte-identical.
.scalafmt.conf
# .scalafmt.conf
version = "3.8.1"
runner.dialect = scala213How to prevent it
- Run
scalafmtAlllocally or in a pre-commit hook before pushing. - Pin the scalafmt
versionin.scalafmt.confso formatting is deterministic. - Keep the same scalafmt config across all contributors.
Related guides
sbt "-Xfatal-warnings" turning warnings into errors in CIFix an sbt build that fails in CI only because of -Xfatal-warnings - a compiler warning that is tolerated loc…
sbt-assembly "deduplicate: different file contents found" in CIFix sbt-assembly "deduplicate: different file contents found in the following" in CI - two jars contribute th…
sbt "Not a valid command" / "Not a valid key" in CIFix sbt "Not a valid command: X" and "Not a valid key: X" in CI - sbt could not parse the command or setting…