Freewind @ Thoughtworks scala java javascript dart 工具 编程实践 月结 math python english [comments admin] [feed]

(2014-09-12) 如何在定义sbt任务时,使用其它key的值

广告: 云梯:翻墙vpn (省10元) 土行孙:科研用户翻墙http proxy (有优惠)

TODO: add link [2759]

如果想使用另一个key的值,可以调用其.value

name := "hello"

version := "1.0"

scalaVersion := "2.11.0"

val mykey = settingKey[Int]("demo key")

mykey := 100

val hello = taskKey[Unit]("demo task")

hello := {println("Hello, world: " + mykey.value)}

运行sbt hello将输出:

Hello, world: 100

.value

value - is a macro defined in sbt.std.MacroValue

Tasks and Settings both produce values that can be used in other tasks and settings. It’s very rare in sbt that a Task doesn’t return something to be used in other tasks. This design allows great flexibility and power when defining complex builds. It’s also drastically simplifies parallel building.

Thanks to: http://stackoverflow.com/a/25808809/342235

comments powered by Disqus