Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change version of Scala that is used by Play, SBT and its plugins?

Is it necessary to change version of Scala that is used by SBT and its plugins ?

I'm using Play Framework 2.1.1-RC2. I want to create new project that will use Scala 2.10.1. To achieve that I did following

  • added dependency "org.scala-lang" % "scala-compiler" % "2.10.1" in Build.scala
  • initialized variable scalaVersion to 2.10.1 in Build.scala

Then I ran play about command and got following output

[test2] $ about
Getting Scala 2.10.1 ...
downloading http://repo1.maven.org/maven2/org/scala-lang/scala-compiler/2.10.1/scala-compiler-2.10.1.jar ...
        [SUCCESSFUL ] org.scala-lang#scala-compiler;2.10.1!scala-compiler.jar (7401ms)
downloading http://repo1.maven.org/maven2/org/scala-lang/scala-library/2.10.1/scala-library-2.10.1.jar ...
        [SUCCESSFUL ] org.scala-lang#scala-library;2.10.1!scala-library.jar (4309ms)
downloading http://repo1.maven.org/maven2/org/scala-lang/scala-reflect/2.10.1/scala-reflect-2.10.1.jar ...
        [SUCCESSFUL ] org.scala-lang#scala-reflect;2.10.1!scala-reflect.jar (2144ms)
downloading http://repo1.maven.org/maven2/org/scala-lang/jline/2.10.1/jline-2.10.1.jar ...
        [SUCCESSFUL ] org.scala-lang#jline;2.10.1!jline.jar (201ms)
:: retrieving :: org.scala-sbt#boot-scala
        confs: [default]
        5 artifacts copied, 0 already retrieved (24386kB/58ms)
[info] This is sbt 0.12.2
[info] The current project is {file:/C:/work/test_projects/test2/}test2
[info] The current project is built against Scala 2.10.1
[info] Available Plugins: play.Project, sbt.PlayProject, com.typesafe.sbteclipse.plugin.EclipsePlugin, com.typesafe.sbtidea.SbtIdeaPlugin
[info] sbt, sbt plugins, and build definitions are using Scala 2.9.2

Last line is what concerns me. It says Scala 2.9.2 is used. How can I change that ? Will it affect what version will be used to compile my code ?

Update: Looks like this way of changing version of compiler didn't work properly. After I run my app I've got following warnings in play console:

[warn] Potentially incompatible versions of dependencies of {file:/C:/work/test_projects/test2/}test2:
[warn]    org.scala-lang: 2.10.1, 2.10.0
[info] Compiling 5 Scala sources and 1 Java source to C:\work\test_projects\test2\target\scala-2.10\classes...
[info] 'compiler-interface' not yet compiled for Scala 2.10.1. Compiling...
[info]   Compilation completed in 8.608 s
[warn] Potentially incompatible versions of dependencies of {file:/C:/work/test_projects/test2/}test2:
[warn]    org.scala-lang: 2.10.1, 2.10.0
[info] play - Application started (Dev)
[warn] Potentially incompatible versions of dependencies of {file:/C:/work/test_projects/test2/}test2:
[warn]    org.scala-lang: 2.10.1, 2.10.0
like image 952
expert Avatar asked Mar 28 '13 04:03

expert


People also ask

How do I switch between Scala versions?

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.

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.

How can I change sbt version?

In the Project tool window, in the source root directory, locate the build. properties file and open it in the editor. In the editor explicitly specify the version of sbt that you want to use in the project.

How do I change the Scala version in Intellij?

In most cases your project JDK is not compatible with Scala or sbt version, try to change the Scala Compile Server SDK. Press Ctrl+Alt+S to open Settings/Preferences dialog. From the options on the left, select Build, Execution, Deployment | Compiler | Scala | Scala Compiler Server.


2 Answers

SBT is a Scala application, and, like all Scala applications, it needs to be abide by Scala's binary compatibility rules. Specifically, versions 2.8, 2.9 and 2.10 are not compatible with each other.

That means that, because the SBT version used by Play was compiled with Scala 2.9.2, then all plugins and all project definitions must be compiled with another 2.9.x version. This is because your Build.scala is not something that is simply executed by SBT, it becomes part of SBT execution.

However, that has relation whatsoever with what version of Scala your application should be compiled with. SBT can use any Scala version, and can even produce multiple Scala versions at the same time -- which is how Scala libraries manage to provide binaries for the multiple Scala versions.

like image 128
Daniel C. Sobral Avatar answered Oct 04 '22 04:10

Daniel C. Sobral


The ultimate goal of my experiments was to change version of Scala compiler used to build my project.

After multiple attempts I concluded that achieving it nicely not possible. I think it's something creators of Play Framework should address.

Setting scalaVersion to 2.10.1-local in Build.scala didn't help much. SBT seem to be going to Maven/Ivy and downloading pieces of 2.10.0 that I don't want. After compiling the app I get bunch of warnings about incompatible dependencies.

I think it happens because {PLAY_HOME}\framework\project\Build.scala has bunch of variable set to 2.10.0.

"Elegant" solution was to tell SBT I'm going to use local copy of Scala by setting following variables in Build.scala

scalaVersion := "2.10.1-local",
autoScalaLibrary := false,
scalaHome := Some(file("/Program Files (x86)/scala/"))

But still if I create IntelliJ IDEA configuration with play idea command resulting project needs some clean up, in particular:

  • Scala facet references missing Scala 2.10.0 library.
  • Module test3-build has dependency on missing Scala 2.9.2 library

I hope my experiments other people who are also learning Play and Scala.

Details are here: http://www.scala-sbt.org/release/docs/Howto/scala.html

like image 33
expert Avatar answered Oct 04 '22 04:10

expert