sbt 0.13.8では、半シーケンシャルなセマンティクスでタスクを実行するためのDef.sequential
関数が追加されました。シーケンシャルタスクを示すために、Compile / compile
タスクと、scalastyle-sbt-pluginによって追加されたCompile / scalastyle
タスクを実行するcompilecheck
というカスタムタスクを作成してみましょう。
設定方法は次のとおりです。
sbt.version=1.9.8
addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "1.0.0")
lazy val compilecheck = taskKey[Unit]("compile and then scalastyle")
lazy val root = (project in file("."))
.settings(
Compile / compilecheck := Def.sequential(
Compile / compile,
(Compile / scalastyle).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
これらのタスクをシーケンスすることができました。