Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Task to get executed after compile

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.

like image 704
Bob V. Avatar asked Mar 17 '26 09:03

Bob V.


1 Answers

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
}
like image 60
marios Avatar answered Mar 22 '26 11:03

marios