每当Runtime
编译配置代码时,如何使sbt运行自定义任务?
鉴于此任务:
val myCustomTask = taskKey[Unit]("Prints a greeting")
myCustomTask := {
println("Hello from myCustomTask!")
}
到目前为止我尝试过的是:
compile := {(compile in Compile) dependsOn myCustomTask}.value
那sbt compile
就是运行时我想要的。
然而,我的自定义任务是不是当我运行运行sbt test
,即使sbt test
品牌SBT也编译运行源,如果需要的话,不仅检验来源:
sbt clean test
...
[info] Compiling 19 Scala sources to /myproject/target/scala-2.11/classes...
[info] Compiling 7 Scala sources to /myproject/target/scala-2.11/test-classes...
..
我读到的test:compile
意思是compile
,但是如何?它似乎并不依赖于compile
自身。
我发现它可以满足triggeredBy
我的要求(SBT在编译后在项目中运行代码)。
这样我得到:
sbt clean test
...
[info] Compiling 19 Scala sources to /myproject/target/scala-2.11/classes...
Hello from myCustomTask!
[info] Compiling 7 Scala sources to /myproject/target/scala-2.11/test-classes...
..
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句