I have a task lazy val task = TaskKey[Unit]
that takes a lazy val setting = SettingKey[String]
as input. I also have three different, independent c
I think you need to write something like
val devTaskSetting = task <<= setting in dev map { s: String =>
println("Setting in Dev is: " + s)
}
You can also define separate task keys, like this
val devTask = TaskKey[Unit]("task", "a simple task experiment") in dev
val stageTask = TaskKey[Unit]("task", "a simple task experiment") in stage
As discussed in How can i make an SBT key see settings for the current configuration?, you can probably use inConfig
as follows.
Change this:
settings = Defaults.defaultSettings ++ Seq(taskTask)
to this:
settings = Defaults.defaultSettings ++
Seq(taskTask) ++
inConfig(dev)(Seq(taskTask)) ++
inConfig(stage)(Seq(taskTask)) ++
inConfig(prod)(Seq(taskTask))
and voilà:
$ sbt
> task
Setting is: default setting
> dev:task
Setting is: default setting
> stage:task
Setting is: stage setting
> prod:task
Setting is: prod setting
If you're interested in digging deeper, inConfig
is defined in sbt.Project
( http://harrah.github.io/xsbt/latest/api/index.html#sbt.Project$ ) as a function to "copy a subgraph of tasks/settings into different scopes" (as @MarkHarrah describes it). Also, take a look at http://eed3si9n.com/sbt-010-guide and scroll down to "changing the scopes" where the author explains how inConfig(conf)(ss)
"scopes the settings ss in to conf only when it isn't scoped yet to a configuration".