sbt 0.13.8 で Def.sequential
という関数が追加されて、準逐次な意味論でタスクを実行できるようになった。
逐次タスクの説明として compilecheck
というカスタムタスクを定義してみよう。これは、まず compile in Compile
を実行して、その後で scalastyle-sbt-plugin の scalastyle in Compile
を呼び出す。
セットアップはこのようになる。
sbt.version=0.13.11
addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "0.8.0")
lazy val compilecheck = taskKey[Unit]("compile and then scalastyle")
lazy val root = (project in file(".")).
settings(
compilecheck in Compile := Def.sequential(
compile in Compile,
(scalastyle in Compile).toTask("")
).value
)
このタスクを呼び出すには、シェルから compilecheck
と打ち込む。もしコンパイルが失敗すると、compilecheck
はそこで実行を中止する。
root> compilecheck
[info] Compiling 1 Scala source to /Users/x/proj/target/scala-2.10/classes...
[error] /Users/x/proj/src/main/scala/Foo.scala:3: Unmatched closing brace '}' ignored here
[error] }
[error] ^
[error] one error found
[error] (compile:compileIncremental) Compilation failed
これで、タスクを逐次実行できた。