sbt "scalac: bad option" in CI
A flag in scalacOptions is not recognized by the Scala compiler in use. Flags differ between Scala 2 and Scala 3 and across minor versions, so an unknown option aborts compilation.
What this error means
The build fails with scalac: bad option: -Xfoo or bad options, naming the unrecognized flag. It is deterministic and tied to the compiler version.
sbt
[error] scalac: bad option: '-Ywarn-unused-import'
[error] (Compile / compileIncremental) Compilation failedCommon causes
Flag removed or renamed across versions
A flag valid in an older Scala 2 line (-Ywarn-unused-import) was renamed or dropped in a newer one, so the current compiler rejects it.
Scala 2 flag used under Scala 3
Scala 3 (Dotty) uses a different flag set; a Scala 2-only option is unknown to it.
How to fix it
Use the flag for your compiler version
Replace the obsolete flag with its current equivalent.
build.sbt
scalacOptions ++= Seq("-Wunused:imports", "-deprecation")Gate flags by Scala version
- Branch scalacOptions on scalaVersion for cross-builds.
- Keep Scala 2 and Scala 3 flag sets separate.
- Check the compiler
-helpoutput for valid flags.
How to prevent it
- Review scalacOptions after a Scala upgrade.
- Gate flags per Scala binary version in cross-builds.
- Consult compiler release notes for renamed flags.
Related guides
sbt "Not a valid command" in CIFix the sbt "Not a valid command" / "Expected" error in CI when an sbt invocation passes a task or command sb…
scalafmt check failed in CIFix sbt scalafmtCheck / scalafmtCheckAll failures in CI when source files are not formatted to the project .s…
sbt "type mismatch; found X required Y" in CIFix the Scala "type mismatch; found : X required: Y" compile error in sbt CI builds where an expression produ…