2

构建.sbt

scalaVersion := "2.11.4"

项目/build.properties

sbt.version=0.13.7

然后

> show scalaVersion
[info] 2.11.4
> show crossScalaVersions
[info] List(2.10.4)
> inspect crossScalaVersions
[info] Setting: scala.collection.Seq[java.lang.String] = List(2.10.4)
[info] Description:
[info]  The versions of Scala used when cross-building.
[info] Provided by:
[info]  */*:crossScalaVersions
[info] Defined at:
[info]  (sbt.Defaults) Defaults.scala:237
[info] Delegates:
[info]  *:crossScalaVersions
[info]  {.}/*:crossScalaVersions
[info]  */*:crossScalaVersions
[info] Related:
[info]  */*:crossScalaVersions

看起来crossScalaVersions应该是List(2.11.4)

看看 SBT 的源代码,我也是这么想的。

crossScalaVersions := Seq(scalaVersion.value)

为什么不crossScalaVersions对应scalaVersion

4

1 回答 1

2

scalaVersion.value是上下文相关的。所以Defaults.scala*/*:scalaVersion来自appConfiguration.value.provider.scalaProvider. 它是用来编译你的项目定义的版本,包括你的build.sbt文件(sbt0.13.7使用2.10.4scala-compiler 来编译你的项目定义)。并且在执行和定义scalaVersion时尚未编译项目定义(包括)的唯一方法。所以,取决于not 。DefaultscrossScalaVersions*/*:crossScalaVersions*/*:scalaVersionproj/*:scalaVersion

只需Provided by与显式scalaVersion := 2.11.4内部比较build.sbt

> inspect scalaVersion
[info] Setting: java.lang.String = 2.11.4
[info] Description:
[info]  The version of Scala used for building.
[info] Provided by:
[info]  {file:/Users/user/dev/proj/}proj/*:scalaVersion
[info] Defined at:
[info]  /Users/user/dev/proj/build.sbt:1
[info] Reverse dependencies (D=derives):
[info]    *:allDependencies
[info]  D *:scalaBinaryVersion
[info]    *:libraryDependencies
[info]    *:scalaInstance
[info]    *:crossScalaVersions
[info]    *:update
[info] Delegates:
[info]  *:scalaVersion
[info]  {.}/*:scalaVersion
[info]  */*:scalaVersion
[info] Related:
[info]  */*:scalaVersion

没有一个(只是空项目):

> inspect scalaVersion
[info] Setting: java.lang.String = 2.10.4
[info] Description:
[info]  The version of Scala used for building.
[info] Provided by:
[info]  */*:scalaVersion
[info] Defined at:
[info]  (sbt.Defaults) Defaults.scala:232
[info] Reverse dependencies:
[info]  *:allDependencies
[info]  *:libraryDependencies
[info]  *:update
[info]  *:scalaInstance
[info] Delegates:
[info]  *:scalaVersion
[info]  {.}/*:scalaVersion
[info]  */*:scalaVersion
[info] Related:
[info]  */*:scalaVersion

所以,你只需要重新定义*/*:scalaVersion你的build.sbt

scalaVersion in GlobalScope := "2.11.2"
于 2015-01-26T13:48:56.143 回答