Skip to content

Instantly share code, notes, and snippets.

@xuwei-k xuwei-k/build.sbt Secret
Last active Feb 7, 2019

Embed
What would you like to do?
並列、かつ指定したprojectだけdocker:publishする
import sbt.complete.DefaultParsers._
import sbt.complete.Parser
val dockerPublish = taskKey[Unit]("ダミーのタスク。本来sbt-native-packagerのやつ")
val dockerPublishParallel = inputKey[Unit]("今回追加するtask")
lazy val commonSettings = Def.settings(
dockerPublish := {
import java.time.LocalTime
println(s"${LocalTime.now()} ${name.value} のpublish開始")
// 並列で実行されるのがわかりやすいように、途中sleepする
Thread.sleep(3000)
println(s"${LocalTime.now()} ${name.value} のpublish終了")
}
)
val allProjects = Seq[ProjectReference](a, b, c)
def distinctParser(exs: Set[String]): Parser[Seq[String]] = {
val base = token(Space) ~> token(NotSpace examples exs)
base.flatMap { ex =>
val (_, notMatching) = exs.partition(GlobFilter(ex).accept)
distinctParser(notMatching).map { result => ex +: result }
} ?? Nil
}
dockerPublishParallel := InputTask.createDyn(
Def.setting{ (_: State) =>
val projectIds = allProjects.collect{ case p: LocalProject => p.project }.toSet
distinctParser(projectIds)
}
){
Def.task(
(projects: Seq[String]) => {
// TODO projects.isEmpty なら逆に全部publish実行、みたいにしておいてもいいかも?
projects.map { p =>
dockerPublish in LocalProject(p)
}.join
}
)
}.evaluated
lazy val a = project
.settings(
commonSettings
)
lazy val b = project
.settings(
commonSettings
)
lazy val c = project
.settings(
commonSettings
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.