我写了一篇关于这个主题的博客文章:使用 sbt-sequential 对任务进行排序 http://eed3si9n.com/sequencing-tasks-with-sbt-sequential.
添加命令别名
这是一个例子。我们将定义一个自定义任务a
在 sub1 和 sub2 中以及b
在根中。实现顺序执行的最简单方法是使用addCommandAlias
,所以我们就这样做。
lazy val a = taskKey[Unit]("a")
lazy val b = taskKey[Unit]("b")
lazy val root = (project in file(".")).
aggregate(sub1, sub2).
settings(addCommandAlias("ab", ";a;b"): _*).
settings(
b := {
println("b")
}
)
lazy val sub1 = (project in file("sub1")).
settings(a := println("a - sub1"))
lazy val sub2 = (project in file("sub2")).
settings(a := println("a - sub2"))
您可以从 shell 运行它sbt ab
.
$ sbt ab
[info] Loading global plugins from ...
[info] Loading project definition from ...
[info] Set current project to root (in build ...)
a - sub2
a - sub1
[success] Total time: 0 s, completed Nov 22, 2014 8:36:18 PM
b
[success] Total time: 0 s, completed Nov 22, 2014 8:36:18 PM
Def.taskDyn
这是另一个例子。这次使用Def.taskDyn
,这也在博客文章中有所体现。
我正在构建一个ScopeFilter
来自aggregate
然后我正在调度任务a
给他们。
lazy val a = taskKey[File]("a")
lazy val b = taskKey[Seq[File]]("b")
lazy val root = (project in file(".")).
aggregate(sub1, sub2).
settings(
b := (Def.taskDyn {
val proj = thisProject.value
val filter = ScopeFilter(inProjects(proj.aggregate: _*))
Def.task {
val allValues = a.all(filter).value
println(allValues.mkString(","))
allValues
}
}).value
)
lazy val sub1 = (project in file("sub1")).
settings(a := new File("a"))
lazy val sub2 = (project in file("sub2")).
settings(a := new File("b"))
您可以从 shell 运行它sbt b
.
$ sbt b
[info] Loading global plugins from ...
[info] Loading project definition from ...
[info] Set current project to root (in build ...)
a,b
[success] Total time: 0 s, completed Nov 23, 2014 9:42:16 PM