Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SBT task dependsOn

Tags:

sbt

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.

like image 393
Joan Avatar asked Dec 16 '16 11:12

Joan


2 Answers

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
like image 66
jkinkead Avatar answered Sep 30 '22 14:09

jkinkead


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
like image 20
Andrei Micu Avatar answered Sep 30 '22 13:09

Andrei Micu