FYI found the way how to create wrapper for stb.Task[Unit] without dependsOn

210 views
Skip to first unread message

Ezh

unread,
Oct 22, 2012, 2:23:04 PM10/22/12
to simple-b...@googlegroups.com
There are a lot of question how to run task inside other task. I found solution for tasks like compile, test and other such tasks.
The only answer is to write custom before task and then use dependsOn. Sometimes this way is inappropriate.

Here is example how to overwrite sbt.Task[Unit] in build.sbt

test in MultiJvm <<= (test in MultiJvm) {
  (test) =>
    val before: sbt.Task[Unit] = task { System.err.println("BEGIN") }
    val after: Unit => Unit = _ => System.err.println("END")
    before doFinally (test map after)
}

If you start multi-jvm:test - sbt
1. Start before method. It initialize environment.
2. Start test and all dependent tasks (so they used prepared environment).
3. Start after method. It deinitialize environment.

It is very handy if you have few overwritten tasks in chain from different plugins and it isn't possible to pass your custom parameters via tasks chain.

King regards,
Alexey
Reply all
Reply to author
Forward
0 new messages