为什么 sbt.Extracted 在 append 方法中删除之前定义的 TaskKey?
Why sbt.Extracted remove the previously defined TaskKey while append method?
sbt.Exctracted中有合适的方法将TaskKey添加到当前状态。假设我有 inState: State
:
val key1 = TaskKey[String]("key1")
Project.extract(inState).append(Seq(key1 := "key1 value"), inState)
当我执行两次时,我遇到了奇怪的行为。我在以下示例中遇到异常:
val key1 = TaskKey[String]("key1")
val key2 = TaskKey[String]("key2")
val st1: State = Project.extract(inState).append(Seq(key1 := "key1 value"), inState)
val st2: State = Project.extract(st1).append(Seq(key2 := "key2 value"), st1)
Project.extract(st2).runTask(key1, st2)
导致:
java.lang.RuntimeException: */*:key1 is undefined.
问题是 - 为什么它会这样工作?是否可以通过多次调用 sbt.Extracted.append
?
在执行特定任务时添加几个 TaskKey
s
示例 sbt 项目是 sbt.Extracted append-example,重现问题只是 运行 sbt fooCmd
Josh Suereth 将 answer 发布到 sbt-dev 邮件列表。引用:
The append
function is pretty dirty/low-level. This is probably a bug in its implementation (or the lack of documentation), but it blows away any other appended setting when used.
What you want to do, (I think) is append into the current "Session" so things will stick around and the user can remove what you've done via "sesison clear" command.
Additonally, the settings you're passing are in "raw" or "fully qualified" form. If you'd for the setting you write to work exactly the same as it would from a build.sbt file, you need to transform it first, so the Scopes match the current project, etc.
We provide a utility in sbt-server that makes it a bit easier to append settings into the current session:
我已经测试了建议的解决方案,效果非常好。
sbt.Exctracted中有合适的方法将TaskKey添加到当前状态。假设我有 inState: State
:
val key1 = TaskKey[String]("key1")
Project.extract(inState).append(Seq(key1 := "key1 value"), inState)
当我执行两次时,我遇到了奇怪的行为。我在以下示例中遇到异常:
val key1 = TaskKey[String]("key1")
val key2 = TaskKey[String]("key2")
val st1: State = Project.extract(inState).append(Seq(key1 := "key1 value"), inState)
val st2: State = Project.extract(st1).append(Seq(key2 := "key2 value"), st1)
Project.extract(st2).runTask(key1, st2)
导致:
java.lang.RuntimeException: */*:key1 is undefined.
问题是 - 为什么它会这样工作?是否可以通过多次调用 sbt.Extracted.append
?
TaskKey
s
示例 sbt 项目是 sbt.Extracted append-example,重现问题只是 运行 sbt fooCmd
Josh Suereth 将 answer 发布到 sbt-dev 邮件列表。引用:
The
append
function is pretty dirty/low-level. This is probably a bug in its implementation (or the lack of documentation), but it blows away any other appended setting when used.What you want to do, (I think) is append into the current "Session" so things will stick around and the user can remove what you've done via "sesison clear" command.
Additonally, the settings you're passing are in "raw" or "fully qualified" form. If you'd for the setting you write to work exactly the same as it would from a build.sbt file, you need to transform it first, so the Scopes match the current project, etc.
We provide a utility in sbt-server that makes it a bit easier to append settings into the current session:
我已经测试了建议的解决方案,效果非常好。