浏览示波器的入门指南,似乎暗示我应该能够执行以下操作:

(其中Build.scala具有来自getting started guide的sampleKeyA / B / C / D)

sampleKeyA := "value 1"

sampleKeyA in compile := "value 2"

compile <<= (compile in Compile, sampleKeyA) map { (result, s) =>
  println("sample key: " + s)
  result
}

但是,当我运行sbt compile时,为sampleKeyA打印的值是“值1”,而不是我期望的“值2”。我想念什么?

最佳答案

首先,在编译中定义sampleKeyA当然是有效的,因为它将设置的范围限定于编译任务。

其次,获得值1,因为您使用的是不带上述范围的sampleKeyA。在编译时将其更改为sampleKeyA,您将获得值2。

要看到这一点,只需启动一个“空” sbt会话并执行以下命令:

> set SettingKey[String]("sampleKeyA") := "value 1"
[info] Reapplying settings...
[info] Set current project to default-a57b70 (in build file:/Users/heiko/tmp/sbt/)
> set SettingKey[String]("sampleKeyA") in compile := "value 2"
[info] Reapplying settings...
[info] Set current project to default-a57b70 (in build file:/Users/heiko/tmp/sbt/)
> sampleKeyA
[info] value 1
> sampleKeyA(for compile)
[info] value 2

关于scala - 为什么sbt不选择此处的范围值?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8594308/

10-10 04:18