Archives par mot-clé : Initialize

Add Custom sbt Task (0.10+)

Simple Call Shell command in build.sbt:

TaskKey[Unit]("echo-simple") := {
List("sh", "-c", "(cd src/main/; echo \"YOUPI\")") ! ;
}

Without Name in build.scala, can be use as dependency:

import sbt.Project.Initialize    
val shEchoTask :  Initialize[Task[Unit]] = (streams) map {
        s => {
          List("sh", "-c", "(echo \"YOUPI\"") ! ;
          s.log.info("Echo")
        }
    }

use it in Build.sbt:

compile.in(Compile) <<= compile.in(Compile) dependsOn(shEchoTask)

With Name in Build.scala, can be use as dependency:

  val shEchoTask = TaskKey[Unit]("echo-simple-task")

  val shEchoAction = (streams) map {
    s => {
     List("sh", "-c", "(echo \"YOUPI\"") ! ;
      s.log.info("Echo")
    }
  }

  lazy val root = Project("root", file("."),
    settings = Defaults.defaultSettings ++ Seq(
    // Link task with action
      shEchoTask in Compile <<= shEchoAction,
    // add dependency
      compile in Compile <<= compile in Compile dependsOn (shEchoTask in Compile)
    ))

partial source: http://comments.gmane.org/gmane.comp.lang.scala.simple-build-tool/1768