SBT:评估任务序列 [英] SBT: Evaluating sequence of tasks
问题描述
我正在尝试获取有关我的 sbt 项目中所有模块的信息.
I am trying to get the information about all modules in my sbt project.
有以下代码
lazy val getModule = taskKey[Module]("get single module info")
lazy val allModules = taskKey[Seq[Module]]("get all modules info")
getModule := Def.task {
Module(name.value, description.value, version.value, organization.value)
}.value,
allModules := Def.task {
val sbtModules = (ThisScope / thisProject).value.aggregate
sbtModules.map { m =>
(ThisScope.in(m) / getModule).value
}
}.value
我收到错误:
[error] problem: Task invocations inside anonymous functions are evaluated independently of whether the anonymous function is invoked or not.
...
[error] /Users/ikryvorotenko/projects/rae/rae-lib/project/SbtToGradlePlugin.scala:27:23: Illegal dynamic reference: m
[error] (ThisScope.in(m) / getModule).value
sbt 有什么可以动态链接任务的吗?基本上我正在寻找类似 Future.sequence
的东西,用于将所有任务结果链接成一个.
Does sbt have anything to chain tasks dynamically?
Basically I'm looking for something like Future.sequence
for chaining all tasks results into one.
推荐答案
任务可能有帮助.
首先,使用Def进行动态计算.taskDyn 允许您使用一个任务的结果来计算另一个.在您的情况下, allModules
应该是 (Def.taskDyn { ... }).value
.
First, Dynamic Computation with Def.taskDyn allows you to use the result of one task to compute the other. In your case, allModules
should be (Def.taskDyn { ... }).value
.
要跨多个子项目等聚合任务,您可以使用 ScopeFilter 和 .all
方法在任务键上.
To aggregate a task across multiple subprojects etc, you can use ScopeFilter and .all
method on a task key.
这篇关于SBT:评估任务序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!