When you write:
`tcWebApp in myTask2` := ...
It doesn't mean "while myTask2 is executing, tcWebApp has the following value," as you want it to. What it does mean is, "if anyone asks myTask2 what value it has for tcWebApp, it will reply as follows." It doesn't have any effect on the global value of tcWebApp
; and if nobody ever asks myTask2
what its value for tcWebApp
is, then setting it in that task has no effect at all. So Task1
will continue to use the global value of tcWebApp
.
I found some related questions on Stack Overflow:
Here Daniel Sobral writes "From what I understand from your question, you want the setting to be different for a dependency depending on what is depending on it. This doesn't make sense -- a dependency either is satisfied or it isn't, and what depends on it doesn't come into the equation." As I understand it, that is the answer to your question.
In order to work around this, instead of attempting to reuse Task1
and Task2
as tasks, reuse the code inside them instead. Have Task1
and Task2
invoke ordinary methods that you define, and then have myTask2
call those same methods, passing them different parameters. In other words don't try to solve your problem with settings; solve it by means of ordinary Scala code.
Or, here's another approach you could take. If you make myTask2
a command rather than a task, you can do what you want. See http://www.scala-sbt.org/release/docs/Extending/Commands.html which says "a command can look at or modify other sbt settings".