I'm using SBT 0.12.0
.
I've two tasks in my project/Build.scala
- helloTask
and u2
defined as follows:
val hello = TaskKey[Unit]("hello", "Prints 'Hello World'")
val helloTask = hello := {
println("Hello World")
}
val u2Task = TaskKey[Unit]("u2") := { println("u2") }
How to make u2
task depend on hellotask
? I used <<=
following the sample as described in Tasks (in the original version of the question it was https://github.com/harrah/xsbt/wiki/Tasks, but the doc has since moved and changed).
u2Task <<= u2Task dependsOn helloTask
But I got reassignment to val
error. Apparently, I cannot get anything with <<=
to work. What am I doing wrong?
I got it to work. I misunderstood the <<=
and :=
operators as assignment operators.
val hello = TaskKey[Unit]("hello", "Prints 'Hello World'")
val helloTask = hello := {
println("Hello World")
}
val u2 = TaskKey[Unit]("u2", "print u2")
val u2Task = u2 <<= hello map {_ => println("u2")}
and the result
> u2
Hello World
u2
I don't see you following the sample very closely - this works for me:
val helloTask = TaskKey[String]("hello")
val u2Task = TaskKey[Unit]("u2")
helloTask := {
println("Hello World")
"Hello World"
}
u2Task := {println("u2")}
u2Task <<= u2Task.dependsOn (helloTask)
The precise reason is that your definition of u2Task has a different type, you can see in the REPL:
scala> val u2Task = TaskKey[Unit]("u2")
u2Task: sbt.TaskKey[Unit] = sbt.TaskKey$$anon$3@101ecc2
scala> val u2Task = TaskKey[Unit]("u2") := {println("u2")}
u2Task: sbt.Project.Setting[sbt.Task[Unit]] = setting(ScopedKey(Scope(This,This,This,This),u2))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With