42

How can I change Scala version in a sbt project?

I would like SBT to check whether the system's Scala version is correct and if it is not the case then download it.

Jacek Laskowski
  • 72,696
  • 27
  • 242
  • 420
Łukasz Lew
  • 48,526
  • 41
  • 139
  • 208
  • In the new sbt 1.x, in the shell: `set scalaVersion := "2.13.1"`, or in build.sbt: `scalaVersion := "2.13.1"`. – bszwej Feb 17 '20 at 08:13

1 Answers1

48

xsbt (0.10+, including the latest 0.13.7)

Change scalaVersion in build.sbt to whatever Scala version your project should be using - see .sbt build definition.

scalaVersion := "2.10.1"

sbt:

As mentioned in RunningSBT, you can:

You can temporarily switch to another version of Scala using ++<version>.
This version does not have to be listed in your build.scala.versions property, but it does have to be in a repository or be a local Scala version you have defined.

But the CrossBuild page is more suited for what you want, as it shows in action how to change the build.scala.versions property.

So you should be able to

set build.scala.versions 2.7.7
reload
set build.scala.versions 2.8.0.RC2
reload

and each time trigger a compilation with a different Scala version.

Jacek Laskowski
  • 72,696
  • 27
  • 242
  • 420
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • @sheki: good point. I have added the xsbt configuration for changing the Scala version used for building your Scala project. – VonC Jul 19 '11 at 13:38
  • @sheki: see my build.sbt as a more complete example of what you usually change in a Scala project with xsbt: https://github.com/VonC/xsbt-template/blob/master/build.sbt – VonC Jul 19 '11 at 13:44
  • 10
    A piece of information I found useful: In case you have a multi-project you can use `scalaVersion in ThisBuild := "2.10.1"` in the main .sbt file to propagate the setting in all sub-projects. – Cristian Vrabie Aug 09 '13 at 18:36
  • @CristianVrabie when `scalaVersion` is defined in the root project's `build.sbt` that aggregates the other submodules, it will work fine, too. You don't need `in ThisBuild`. – Jacek Laskowski Jan 07 '14 at 22:14