I want to override the value of a SettingKey b only when computing SettingKey a1.
import sbt._
import sbt.Keys._
object Build extends Build {
val a1Key = SettingKey[String]("a1", "")
val a2Key = SettingKey[String]("a2", "")
val bKey = SettingKey[String]("b", "")
lazy val rootProject = Project("P", file(".")).settings(
bKey := "XXX",
a1Key <<= bKey((x) => ">>>"+x+"<<<"),
a2Key <<= bKey((x) => ">>>"+x+"<<<")
) .settings(
bKey in a1Key := "YYY" //providing custom value in setting scope
)
}
Current result is
> a1
[info] >>>XXX<<<
> a2
[info] >>>XXX<<<
> b
[info] XXX
…but I’m aiming at seeing YYY as the value of a1:
> a1
[info] >>>YYY<<<
> a2
[info] >>>XXX<<<
> b
[info] XXX
Better real world example than above is when you want to add some resources to your build only in runtime configuration, and some other resources when the application is packaged. For example building GWT app public resources served by server during development-mode and during production are different. It would be nice for example to customize setting resource-directories for run and package tasks.
You need to set
a1Keyanda2Keyto allow forbKeyto be overridden in the first place:That way, computing
a1Keywill use the more specific valueMeepand while computinga2Key, sbt would “look for” the definition ofbKey in a2Keyand then, because it doesn’t “find” it, falls back to the more generalbKey(in the default scope), which is defined and therefore used.Edit: this unfortunately means, that unless whoever provides the definitions of the
a1Keyanda2Keysettings also explicitly provides the required extension points (in the form of setting-scoped dependencies), you cannot override the dependencies. That is at least how I understand it.