在SBT中多次运行任务

时间:2017-02-07 12:11:23

标签: scala sbt

我想在我的sbt版本中多次运行我的任务。

lazy val sampleTask = taskKey[Unit]("A sample task.")

val dynamic = Def.taskDyn {
    println("Called dynamic")
    Def.task {
      println("Executing dynamic task")
    }
}

lazy val library = (project in file("library")).
settings(
 sampleTask := {
   for (i <- (1 until 4)) {
     println(s"Loop $i")
     val num = dynamic.value
   }
 }
)

SBT默认缓存任务的执行,结果我得到:

Called dynamic
Executing dynamic task
Loop 1
Loop 2
Loop 3

我希望每次调用时都运行动态任务,所以我得到:

Called dynamic
Executing dynamic task
Loop 1
Called dynamic
Executing dynamic task
Loop 2
Called dynamic
Executing dynamic task
Loop 3

是否可以强制sbt在一个版本中多次运行相同的任务?

1 个答案:

答案 0 :(得分:0)

感谢@ seth-tisue发表评论。我创建了命令,并且我多次调用任务:https://github.com/otrebski/sbt-flaky/commit/308a5dd34afbcbfcc4da9a71ec16b20e0c168ec0#diff-fba3577a701d9ead931278034fe240a6

def flaky = Command("flaky")(parser) {(state,args) =>
  val taskKey = Keys.test in Test
  for (i <- (1 to count)) {
    println(s"Running tests: $i")
    Project.runTask(taskKey, state)
  }
}