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]


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 - 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:

comments powered by Disqus