SBT: Evaluating sequence of tasks

我是研究僧i 提交于 2020-12-12 21:23:34

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!