8

Since SBT 0.13.13 this is deprecated (<<= is deprecated):

compile in Compile <<= (compile in Compile).dependsOn(apiDoc)

So the only way to do I found is this:

compile in Compile := {
  apiDoc.value
  (compile in Compile).value
}

But now I have a warning about a useless expression apiDoc.value. But this is not useless!
I can't find any documentation about what is the new way to do.

Joan
  • 4,079
  • 2
  • 28
  • 37

2 Answers2

16

I haven't found docs for this, but you can create a dependsOn like:

compile.in(Compile) := compile.dependsOn(apiDoc).value

Note that if you're doing this for an InputTask, you'll need to use evaluated instead of value:

myInputTask := myInputTask.dependsOn(apiDoc).evaluated
jkinkead
  • 4,101
  • 21
  • 33
  • As of sbt `1.1.1`, this approach now works: https://stackoverflow.com/a/44669226/1080804 – ecoe May 24 '18 at 17:26
2

I've struggled with the problem of depending tasks and it all became clear after I read this page: http://www.beyondthelines.net/computing/understanding-sbt/

TLD;DR: to make a task dependent on another inside a task definition, you have to use Def.sequential (examples from the page):

lazy val A = taskKey[Unit]("Task A")
A in Global := { println("Task A") }
 
lazy val B = taskKey[Unit]("Task B")
B in Global := { println("Task B") }
 
lazy val C = taskKey[Unit]("Task C")
C := Def.sequential(A, B).value

So for your case, it would be:

compile in Compile := Def.sequential(apiDoc, compile in Compile).value

Or, if you use the new sbt syntax and have different scoping:

ThisBuild / Compile / compile := Def.sequential(apiDoc, Compile / compile).value
Andrei Micu
  • 3,159
  • 1
  • 17
  • 20