sbt 如何选择使用哪个 Scala 版本?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14572148/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How does sbt choose which Scala version to use?
提问by Mark
I have multiple projects in my sbt build. I'm trying to upgrade to Scala 2.10 from 2.9.1, so in my build.sbt file I put
我的 sbt 构建中有多个项目。我正在尝试从 2.9.1 升级到 Scala 2.10,所以在我的 build.sbt 文件中我放了
scalaVersion := "2.10.0"
This seemed to work, because in my top-level project in sbt I get:
这似乎有效,因为在 sbt 的顶级项目中,我得到:
> scala-version
[info] 2.10.0
However, when I switch to one of the other projects:
但是,当我切换到其他项目之一时:
> project web-client
[info] Set current project to web-client (in build file:/C:/Users/...
[web-client] $ scala-version
[info] 2.9.1
You see the version has now changed back to 2.9.1! How do I force the same Scala version to be used across all my projects?
你看版本现在已经改回2.9.1了!如何强制在我的所有项目中使用相同的 Scala 版本?
回答by Mark
I found out scoping the scalaVersion to ThisBuild will set it for all sub-projects. Details are here: http://www.scala-sbt.org/release/docs/Getting-Started/Multi-Project.htmlat the bottom, but here is what it says:
我发现将 scalaVersion 范围限定为 ThisBuild 将为所有子项目设置它。详细信息在这里:http: //www.scala-sbt.org/release/docs/Getting-Started/Multi-Project.html在底部,但它是这样说的:
To set it only once, it is enough to write, in the main build.sbt file, the following line:
要只设置一次,在主 build.sbt 文件中写入以下行就足够了:
scalaVersion in ThisBuild := "2.10.0"
回答by Daniel C. Sobral
SBT has a default Scala version. You need to add the scalaVersionsetting to all subprojects if you wish to change it. The most common way of doing that is having a "common settings" value that is added to all projects at the root level, through project/Build.scala.
SBT 有一个默认的 Scala 版本。scalaVersion如果您想更改它,您需要将设置添加到所有子项目。最常见的方法是将“通用设置”值添加到根级别的所有项目中,通过project/Build.scala.

