如何更改Play,SBT及其插件使用的Scala版本? [英] How can I change version of Scala that is used by Play, SBT and its plugins?

查看:168
本文介绍了如何更改Play,SBT及其插件使用的Scala版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有必要更改SBT及其插件使用的Scala版本?

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

我正在使用Play Framework 2.1.1-RC2。我想创建将使用Scala 2.10.1的新项目。为了实现这一点,我做了以下

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


  • 添加了依赖org.scala-lang%scala-compiler% 2.10.1 in Build.scala

  • 初始化变量 scalaVersion 至2.10.1 in Build.scala

  • 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

最后一行是关注我的。它说使用了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


推荐答案

SBT是一个Scala应用程序,与所有Scala应用程序一样,它需要遵守Scala的二进制兼容性规则。具体来说,版本2.8,2.9和2.10彼此不兼容。

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.

这意味着,因为Play使用的SBT版本是使用Scala 2.9.2编译的,所有插件和所有项目 definitions 必须使用另一个2.9.x版本进行编译。这是因为你的 Build.scala 不是由SBT简单执行的,它成为SBT执行的一部分

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.

但是,这与您应用程序应编译的Scala版本有任何关系。 SBT可以使用任何Scala版本,甚至可以同时生成多个Scala版本 - 这就是Scala库为多个Scala版本提供二进制文件的方式。

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.

这篇关于如何更改Play,SBT及其插件使用的Scala版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆