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

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

问题描述

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

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

我使用的是 Play 框架 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

  • Build.scala
  • 中添加了依赖"org.scala-lang" % "scala-compiler" % "2.10.1"
  • Build.scala 中将变量scalaVersion 初始化为2.10.1
  • added dependency "org.scala-lang" % "scala-compiler" % "2.10.1" in Build.scala
  • initialized variable scalaVersion to 2.10.1 in Build.scala

然后我运行 play about 命令并得到以下输出

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	est_projects	est2	argetscala-2.10classes...
[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 编译的,那么所有插件和所有项目定义都必须用另一个 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天全站免登陆