Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does sbt choose which Scala version to use?

Tags:

scala

sbt

I have multiple projects in my sbt build. I'm trying to upgrade to Scala 2.10 from 2.9.1, so in my build.sbt file I put

scalaVersion := "2.10.0"

This seemed to work, because in my top-level project in sbt I get:

> scala-version
[info] 2.10.0  

However, when I switch to one of the other projects:

> project web-client
[info] Set current project to web-client (in build file:/C:/Users/...
[web-client] $ scala-version
[info] 2.9.1  

You see the version has now changed back to 2.9.1! How do I force the same Scala version to be used across all my projects?

like image 532
Mark Avatar asked Jan 28 '13 22:01

Mark


People also ask

Which Scala version does sbt use?

sbt's Scala version sbt uses that same version of Scala to compile the build definitions that you write for your project because they use sbt APIs. This version of Scala is fixed for a specific sbt release and cannot be changed. For sbt 1.7. 1, this version is Scala 2.12.

Is Scala installed with sbt?

sbt will download Scala for you. If you install sbt-extras (basically just a script) you don't even need to download sbt : it will automatically download the sbt launcher you need. Very handy since you just need to specify sbt. version in your build.

What is the difference between sbt and Scala?

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.

How do I find Scala version?

Check Scala Version Using scala CommandWrite the scala command to your terminal and press enter. After that, it opens Scala interpreter with a welcome message and Scala version and JVM details.


2 Answers

I found out scoping the scalaVersion to ThisBuild will set it for all sub-projects. Details are here: http://www.scala-sbt.org/release/docs/Getting-Started/Multi-Project.html at the bottom, but here is what it says:

To set it only once, it is enough to write, in the main build.sbt file, the following line:

scalaVersion in ThisBuild := "2.10.0"
like image 50
Mark Avatar answered Oct 01 '22 21:10

Mark


SBT has a default Scala version. You need to add the scalaVersion setting to all subprojects if you wish to change it. The most common way of doing that is having a "common settings" value that is added to all projects at the root level, through project/Build.scala.

like image 44
Daniel C. Sobral Avatar answered Oct 01 '22 19:10

Daniel C. Sobral