Task to get executed after compile

463 Views Asked by At

I need a task myTask to get executed after compile task is finished. I have tried a number of things I've found on this forum:

  • using dependsOn --> only working if "sbt myTask" is explicitly called on sbt prompt. But I need myTask to be executed automatically, whenever compile is executed.
  • using triggeredBy --> myTask gets never called

Doing the other way around works like a charm, although it is not what I want. I mean, doing:

(compile in Compile) <<= (compile in Compile) dependsOn myTask

makes myTask to get executed in the first place, and then the compile task is executed. But I need myTask to get executed after compile is over.

Any idea?

Thanks a lot.

1

There are 1 best solutions below

11
On

Here is one way to modify the compile task to invoke anotherTask. Add the following in your build.sbt.

lazy val anotherTask = taskKey[Unit]("another task")

anotherTask := println("hello")

compile in Compile := {
    val compileAnalysis = (compile in Compile).value
    anotherTask.value
    compileAnalysis
}