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

后端 未结 2 1615
小蘑菇
小蘑菇 2021-02-05 16:08

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.

相关标签:
2条回答
  • 2021-02-05 16:33

    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.

    0 讨论(0)
  • 2021-02-05 16:37

    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

    0 讨论(0)
提交回复
热议问题