1. Def.sequentialによるシーケンシャルタスクの定義

Def.sequentialによるシーケンシャルタスクの定義 

sbt 0.13.8では、半シーケンシャルなセマンティクスでタスクを実行するためのDef.sequential関数が追加されました。シーケンシャルタスクを示すために、Compile / compileタスクと、scalastyle-sbt-pluginによって追加されたCompile / scalastyleタスクを実行するcompilecheckというカスタムタスクを作成してみましょう。

設定方法は次のとおりです。

project/build.properties 

sbt.version=1.9.8

project/style.sbt 

addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "1.0.0")

build.sbt 

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

これらのタスクをシーケンスすることができました。