Search code examples
scalaplayframeworksbtplayframework-2.2

I can't set the default version of Scala for Play


I can't set the version of Scala for a Play application:

//project/Build.scala

import sbt._
import play.Project._
import sbt.Keys._

object AppBuild extends Build {
  val appName = .....
  val appVersion = .....
  val appDependencies = Seq(jdbc, anorm)

  val main = play.Project(appName, appVersion, appDependencies)
  lazy val buildSettings = Seq(
    organization := "fdsfds"
    ,version := "1.0-SNAPSHOT123"
    ,scalaVersion := "2.10.3"
  )
}

I seemed like it didn't work. Then I commented out version and scalaVersion and created a new file:

//project/build.sbt

version in ThisBuild := "0.1"

scalaVersion in ThisBuild := "2.10.3"

And yet when I say play is responds:

play 2.2.1 built with Scala 2.10.2 (running Java 1.7.0_25), http://www.playframework.com
[my_app] $ show scala-version
[info] 2.10.2

I'm using sbt 0.13 and play 2.2.1. The default (and the only I guess) scala version on my computer is 2.10.3.

How do I make this app use scala 2.10.3 by default?


Solution

  • By default Play is using Scala used by sbt launcher, which is configured in $PLAY_HOME/framework/sbt/play.boot.properties.

    You should be able to modify the version of Scala, Play is using by (for example) adding it to your build.sbt. Be sure to add it after a line play.Project.playScalaSettings, which defines default settings for Play. So if you add scalaVersion := "2.10.3" at the end of your build.sbt it should work.

    For example, when you create a new play application your build.sbt should look more or less like this

    name := "Example"
    
    version := "1.0-SNAPSHOT"
    
    libraryDependencies ++= Seq(
      jdbc,
      anorm,
      cache
    )     
    
    play.Project.playScalaSettings
    
    scalaVersion := "2.10.3"
    

    Now if you run application (or console for that matter), you'll see it's using the correct version

    Welcome to Scala version 2.10.3 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_45).
    Type in expressions to have them evaluated.
    Type :help for more information.
    

    also show scala-version should return proper version

    [Example] $ show scala-version
    [info] 2.10.3