问题
I am trying to get the information about all modules in my sbt project.
Having the following code
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
I'm getting the errors:
[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
Does sbt have anything to chain tasks dynamically?
Basically I'm looking for something like Future.sequence
for chaining all tasks results into one.
回答1:
There are a few features described in Tasks that might be helpful.
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
.
To aggregate a task across multiple subprojects etc, you can use ScopeFilter and .all
method on a task key.
来源:https://stackoverflow.com/questions/55315179/sbt-evaluating-sequence-of-tasks