是否有必要更改 SBT 及其插件使用的 Scala 版本?
我正在使用 Play 框架 2.1.1-RC2。我想创建将使用 Scala 2.10.1 的新项目。为了实现这一点,我做了以下
"org.scala-lang" % "scala-compiler" % "2.10.1"
在 Build.scala
scalaVersion
到 2.10.1 中 Build.scala
然后我跑了
play about
命令并得到以下输出[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
最后一行是我所关心的。它说使用了 Scala 2.9.2。我该如何改变?会不会影响用什么版本编译我的 代码 ?
更新:看起来这种更改编译器版本的方式无法正常工作。运行我的应用程序后,我在 Play 控制台中收到以下警告:
[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
最佳答案
SBT 是一个 Scala 应用程序,和所有 Scala 应用程序一样,它需要遵守 Scala 的二进制兼容性规则。具体来说,版本 2.8、2.9 和 2.10 彼此不兼容。
这意味着,因为 Play 使用的 SBT 版本是用 Scala 2.9.2 编译的,所以所有插件和所有项目定义都必须用另一个 2.9.x 版本编译。这是因为您的 Build.scala
不是简单地由 SBT 执行的东西,它成为 SBT 执行的一部分。
但是,这与您的应用程序应该使用什么版本的 Scala 编译有关。 SBT 可以使用任何 Scala 版本,甚至可以同时生成多个 Scala 版本——这就是 Scala 库设法为多个 Scala 版本提供二进制文件的方式。
关于scala - 如何更改 Play、SBT 及其插件使用的 Scala 版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15674406/