翻阅范围的入门指南,似乎暗示我应该能够这样做:
(其中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打印的值是"value 1",而不是我期望的"value 2“。我遗漏了什么?
发布于 2011-12-22 17:10:44
首先,在编译中定义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发布于 2011-12-22 04:29:33
它选择了value 1,因为value 2的作用域在编译中,但您得到的是通用版本。如果你写了sampleKeyA in Compile,它就会工作。或者,可能是in compile --我认为声明是不正确的,因为作用域compile实际上并不存在。
https://stackoverflow.com/questions/8594308
复制相似问题