Add task to Build.scala

sbt

Solution

The part where you declare the `TaskKey` is the same in either format: `val myTask = taskKey...`.

The part where you write out your `Initialize[Task[T]]` is the same: `myTask := ...`.

The only difference is the context in which the latter thing appears.

In the `.sbt` format, it appears by itself, separated from other things by blank lines.

In the `.scala` format, you have to add the setting to the project. That's documented at http://www.scala-sbt.org/release/docs/Getting-Started/Full-Def.html and is the same regardless of whether we're talking about a task or a regular setting.

Here's a complete working example:

import sbt._
object MyBuild extends Build {
  val myTask = taskKey[Unit]("...")
  lazy val root =
    Project(id = "MyProject", base = file("."))
      .settings(
        myTask := { println("hello") }
    )
}

Problem

The document http://www.scala-sbt.org/0.13.0/docs/Detailed-Topics/Tasks.html explains how to add a task to build.sbt, but how do you add one to build.scala? Thanks

Original source