为什么scalaInstance与sbt中的scalaVersion不同?

时间:2014-07-07 20:29:30

标签: sbt

build.sbt

val Backend = config("backend")

inConfig(Backend)(Defaults.configSettings)

scalaVersion in Backend := "2.11.2-SNAPSHOT"

sbt repl:

> show backend:scalaInstance
[info] Scala instance{version label 2.10.4, actual version 2.10.4, library jar: /home/masgui/.sbt/boot/scala-2.10.4/lib/scala-library.jar, compiler jar: /home/masgui/.sbt/boot/scala-2.10.4/lib/scala-compiler.jar}

> backend:scalaVersion
[info] 2.11.2-SNAPSHOT

当前的工作:

lazy val v = Project(
    id = "a",
    base = file("woot"),
    settings = Project.defaultSettings ++ Seq(
        offline := true,
        scalaVersion := "2.11.2-SNAPSHOT"
    )
)

// ...
scalaInstance in (Backend, Revolver.reStart) := (scalaInstance in v).value

修改

当我向后端添加Classpaths.ivyBaseSettings时,它会忽略ivyConfigurations += Backend

> show ivyConfigurations
[info] List(..., backend)

> backend:update
Cannot add dependency 'com.scalakata#backend_2.11;0.1-20140706T182100' to configuration 'backend' of module com.scalakata#plugin;0.1-20140709T150113 because this configuration doesn't exist!

修改 我用你之前的一个awnser解决了这个问题:Copy a single dependency jar into a folder via build.sbt

1 个答案:

答案 0 :(得分:1)

TL; DR;

您还必须将Classpaths.ivyBaseSettingsClasspaths.jvmBaseSettingsDefaults.compileBase添加到Backend配置中。

build.sbt

val Backend = config("backend") 

inConfig(Backend)(Classpaths.ivyBaseSettings ++ Classpaths.jvmBaseSettings ++ Defaults.compileBase ++ Defaults.configSettings)

scalaVersion in Backend := "2.11.1"

更长的版本

scalaInstance配置中的任务Backend未定义,因此sbt委托默认为scalaInstance

[info] Delegates:
[info]  backend:scalaInstance
[info]  *:scalaInstance
[info]  {.}/backend:scalaInstance
[info]  {.}/*:scalaInstance
[info]  */backend:scalaInstance
[info]  */*:scalaInstance

如果您查看其定义的位置,您可以在*:scalaInstance

中看到它
> inspect definitions scalaInstance
[info] 
[info]  *:scalaInstance

如果您希望定义它,则必须将Defaults.compileBase添加到Backend配置中。

您可以确认它未在Backend范围内定义。

> inspect definitions scalaInstance
[info] 
[info]  *:scalaInstance
[info]  backend:scalaInstance

但这还不够,如果你检查show backend:scalaInstance的输出,你会发现它仍然是2.10.x

> show backend:scalaInstance
[info] Scala instance{version label 2.11.1, actual version 2.10.4, library jar: /home/lpiepiora/.sbt/boot/scala-2.10.4/lib/scala-library.jar, compiler jar: /home/lpiepiora/.sbt/boot/scala-2.10.4/lib/scala-compiler.jar}

我们需要通过添加Classpaths.ivyBaseSettings ++ Classpaths.jvmBaseSettings来配置正确的类路径。

show backend:scalaInstance显示正确的版本。

> show backend:scalaInstance
[info] Scala instance{version label 2.11.1, actual version 2.11.1, library jar: /home/lpiepiora/.ivy2/cache/org.scala-lang/scala-library/jars/scala-library-2.11.1.jar, compiler jar: /home/lpiepiora/.ivy2/cache/org.scala-lang/scala-compiler/jars/scala-compiler-2.11.1.jar}
[success] Total time: 0 s, completed 08-Jul-2014 20:32:18