Skip to content
Latchkey

scalac Command: Compile Scala in CI

scalac compiles Scala source files into JVM class files.

scalac is the Scala compiler. Real projects build through sbt or Mill, but scalac shows up in CI scripts and minimal images. Its flags control output, classpath, and how strictly warnings are enforced.

Common flags

  • -d OUT - output directory or .jar for class files
  • -classpath / -cp PATH - dependency class path
  • -deprecation - emit warnings for deprecated API use
  • -feature - warn on language features requiring an import
  • -Xfatal-warnings - turn all warnings into errors
  • -release 17 - target JVM bytecode and API level
  • -language:postfixOps - enable a specific language feature

Example in CI

Compile a Scala source tree strictly, failing on any warning:

shell
scalac -deprecation -feature -Xfatal-warnings -release 17 -d build src/*.scala

Common errors in CI

  • error: not found: value X - unresolved identifier or missing import
  • error: type mismatch; found: A, required: B
  • error: object X is not a member of package Y - missing dependency on classpath
  • error: No warnings can be incurred under -Werror (Scala 3) - a warning failed the build

Key takeaways

  • Use -Xfatal-warnings (Scala 2) or -Werror (Scala 3) to keep CI strict.
  • -release N pins both bytecode and the JDK API surface.
  • Most CI failures are "not found" identifiers or type mismatches.

Related guides

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