This guide covers how to configure Scala versions, compiler options, and switch between different Scala versions in your sbt build.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/sbt/sbt/llms.txt
Use this file to discover all available pages before exploring further.
Setting the Scala Version
The most basic Scala configuration is setting the version using thescalaVersion key:
build.sbt
build.sbt
The
scalaVersion setting determines which version of the Scala compiler is used for building your project.Scala Organization
By default, sbt usesorg.scala-lang as the Scala organization. This is an advanced setting for Scala language clones:
build.sbt
Configuring Compiler Options
ThescalacOptions task controls options passed to the Scala compiler:
build.sbt
Common Scala 2 Compiler Options
Common Scala 3 Compiler Options
build.sbt
Scala Binary Version
ThescalaBinaryVersion is automatically derived from scalaVersion and describes binary compatibility:
Cross-Building
For projects that need to support multiple Scala versions, usecrossScalaVersions:
build.sbt
+ command prefix:
Switching Scala Versions
Use the++ command to switch Scala versions:
Using a Local Scala Installation
You can use a local Scala installation instead of fetching from Maven:build.sbt
Scala Instance Configuration
Advanced users can configure the Scala instance directly:build.sbt
Configuration Per Configuration
You can set different compiler options for different configurations:build.sbt
Scala 2 vs Scala 3
Key differences when configuring:| Feature | Scala 2 | Scala 3 |
|---|---|---|
| Binary Version | 2.12, 2.13 | 3 |
| Compiler Bridge | scala2-sbt-bridge | scala3-sbt-bridge |
| Warning Options | -Ywarn-* | -W* |
| Language Features | -language:* | Built-in or -language:* |
sbt automatically handles different compiler bridges for Scala 2 and Scala 3, so you don’t need to configure this manually.
Dynamic Scala Versions
You can use dynamic version strings that sbt resolves:build.sbt
scalaDynVersion task performs this resolution.
Best Practices
Pin your Scala version
Always specify an exact
scalaVersion in your build.sbt for reproducible builds.Use crossScalaVersions for libraries
If you’re building a library, support multiple Scala versions using
crossScalaVersions.Keep compiler options consistent
Use the same compiler options across configurations unless you have a specific reason not to.