Sequencing and overriding tasks in SBT Sequencing and overriding tasks in SBT heroku heroku

Sequencing and overriding tasks in SBT


See http://www.scala-sbt.org/0.13/docs/Howto-Sequencing.html for how to sequence tasks.

So something like:

stage in Universal := Def.sequential(  stage in Universal,  stageCleanupTask)


Let me start by saying that baseDirectory.value / "modules" / "a" / "target" is not the kind of path definition you want to use since it's much better to make use of the settings SBT provides you. What I recommend is using (target in moduleName).value.

As for your main question, I recommend you do this:

val stageCleanupTask = taskKey[sbt.File]("Clean after stage task")lazy val root = project.in(file("."))  ...  .settings(    stageCleanupTask := {      val a = (stage in Universal).value      val log = streams.value.log      if (sys.env.getOrElse("POST_STAGE_CLEAN", "false").equals("true")) {        log.info("Cleaning submodules' target directories")        sbt.IO.delete((target in a).value)        sbt.IO.delete((target in b).value)        sbt.IO.delete((target in c).value)      }      a    },    stage <<= stageCleanupTask

I just tested in one of my own projects and it worked flawlessly.


Edit 1

My battery is dying so I can't look into this further but it might be the thing you're looking for.


Replace following code

stage := {  val f = (stage in Universal).value  stageCleanupTask.value  f}

By this one

import com.typesafe.sbt.packager.universal.UniversalPlugin.autoImport.Universalstage := Def.taskDyn {  val x = (stage in Universal).value  Def.task {    stageCleanupTask.value    x  }}.value

That will lead to sequencing tasks and work as you expected.