fommil
fommil

Reputation: 5885

How to define a task that is called for the root project only?

When I define a task it gets called for each project in a multi-project build:

import sbt._
import Keys._
import IO._

object EnsimePlugin extends Plugin {

  val ensime = TaskKey[Unit](
    "generateEnsime",
    "Generate the ENSIME configuration for this project")

  override val projectSettings = Seq(
    ensime := generateEnsime (
      (thisProject in Test).value,
      (update in Test).value
    )
  )

  private def generateEnsime(proj: ResolvedProject, update: UpdateReport): Unit = {
    println(s"called by ${proj.id}")
  }    
}

How can I define a task so that it is only called for the root project?

They are usually discouraged, but is this perhaps a valid use of a Command? e.g. like the sbt-idea plugin.

Upvotes: 3

Views: 324

Answers (1)

Jacek Laskowski
Jacek Laskowski

Reputation: 74749

From the official docs about Aggregation:

In the project doing the aggregating, the root project in this case, you can control aggregation per-task.

It describes aggregate key scoped to a task with the value false as:

aggregate in update := false

Use commands for session processing that would otherwise require additional steps in a task. It doesn't necessarily mean it's harder in tasks, but my understanding of commands vs tasks is that the former are better suited for session manipulation. I might be wrong, though in your particular case commands are not needed whatsoever.

Upvotes: 3

Related Questions