I'm building a scala project(writen in scala 2.11) with SBT 1.x.There are a few "versions of scala" which made me puzzle.
SBT 1.x => scala 2.12
SBT plugin => scala 2.x
My project => scala 2.11
Please help me to figure out what's the difference or relationship between them.And how SBT tells them apart when compiling or running the project?
SBT is tied to a specific project defined by a build. sbt file in a way that $ sbt console will load up the same REPL environment as $ scala but with the addition of all of the project code and dependencies defined in the build available for import. Also, it will use the version of Scala defined by build.
sbt needs to obtain Scala for a project and it can do this automatically or you can configure it explicitly. The Scala version that is configured for a project will compile, run, document, and provide a REPL for the project code.
sbt is a popular tool for compiling, running, and testing Scala projects of any size. Using a build tool such as sbt (or Maven/Gradle) becomes essential once you create projects with dependencies or more than one code file.
You can use several different tools to build your Scala projects, including Ant, Maven, Gradle, and more.
The Scala version used by sbt itself and its plugins is completely independent from the Scala version used to compile the code in your project. The sbt version determines the Scala version it uses:
You can set this version in project/build.properties
, for example:
sbt.version = 1.1.1
The sbt plugins you want to use have to be compatible with the given version of sbt (and many are cross-compiled with both 0.13 and 1.x).
To set the version of Scala you want to use for the code in you project, use scalaVersion
setting in your build.sbt
:
scalaVersion := "2.12.4"
Again, it's independent from the version for sbt. You can also cross-compile your code for several Scala versions:
scalaVersion := "2.12.4"
crossScalaVersions := Seq("2.11.12", "2.12.4")
Then if you run compile
in sbt, it will use Scala 2.12.4, and if you run +compile
, it will first compile it with Scala 2.11.12 and then with 2.12.4. See sbt docs for more about Cross-building.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With