Skip to content
Latchkey

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 failed

Common 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

  1. Branch scalacOptions on scalaVersion for cross-builds.
  2. Keep Scala 2 and Scala 3 flag sets separate.
  3. Check the compiler -help output 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

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →