Created
November 26, 2019 13:04
-
-
Save xuwei-k/4e1c267767fef81a871a576c13d37bbc to your computer and use it in GitHub Desktop.
sbt task sequential
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val someTask = taskKey[Unit]("") | |
val commonSettings = Def.settings( | |
someTask := { | |
println(name.value + " 開始") | |
Thread.sleep(500) | |
println(name.value + " 終了") | |
} | |
) | |
lazy val p1 = project.settings(commonSettings) | |
lazy val p2 = project.settings(commonSettings) | |
lazy val p3 = project.settings(commonSettings) | |
// わざとcommonSettings設定しない | |
lazy val p4 = project | |
TaskKey[Unit]( | |
"someTaskSequential", | |
s"`${someTask.key.label}` を直列で実行" | |
) := Def.taskDyn { | |
val extracted = Project.extract(state.value) | |
val tasks :+ last = extracted.structure.allProjectRefs.sortBy(_.project).map { p => | |
// 定義されてないsub projectがあるとエラーになってしまうので、それを考慮して `.?` にしている(定義されてないsub projectではNoneになる) | |
// 定義されてないsub projectが存在しないなら `.toTask` | |
// Def.sequentialの最初の引数は `Seq[Initialize[sbt.Task[Unit]]]` である必要があるので、Option[Unit]をUnitにするために結果をmap | |
(someTask in p).?.map(_ => ()) | |
} | |
Def.sequential(tasks, last) | |
}.value |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment