How to depend on the settings in the "current" configuration

How can I declare 2 custom sbt parameters, for example A and B, define B in the Global config area with content that depends on A, define A differently in several configuration areas so that the resulting B value is different in each configuration, although B is defined only once?

Consider, for example, targetHost below, defined differently in remote than in another configuration, and scriptContent depending on it:

 object MyBuild extends Build { lazy val remote = config("remote") describedAs ("configuration for remote environement ") lazy val targetHost = settingKey[String]("private hostname of master server") lazy val scriptContent = settingKey[String]("Some deployment script") lazy val root: Project = Project("meme", file(".")). settings( name := "hello", targetHost := "localhost", targetHost in remote := "snoopy", scriptContent := s""" # some bash deployment here /usr/local/uberDeploy.sh ${targetHost.value} """ ) } 

I would like scriptContent have a different value in both areas of the configuration, but since it depends on targetHost in the Global , its value is always the same:

 > scriptContent [info] [info] # some bash deployment here [info] /usr/local/uberDeploy.sh localhost [info] > remote:scriptContent [info] [info] # some bash deployment here [info] /usr/local/uberDeploy.sh localhost [info] 

While I would like to get the following:

 > scriptContent [info] [info] # some bash deployment here [info] /usr/local/uberDeploy.sh localhost [info] > remote:scriptContent [info] [info] # some bash deployment here [info] /usr/local/uberDeploy.sh snoopy [info] 
+5
source share
1 answer

Found! My question is actually a duplicate (sorry ...), and the most appropriate answer is here: How can I make the SBT key, see the settings for the current configuration?

=> we need to apply the settings several times, once for each area, to force a re-evaluation of the contents of scriptSetting :

 import sbt._ import sbt.Keys._ object MyBuild extends Build { lazy val remote = config("remote") describedAs ("configuration for remote environement ") lazy val targetHost = settingKey[String]("private hostname of master server") lazy val scriptContent = settingKey[String]("Some deployment script") lazy val scriptSettings = Seq( scriptContent := s""" # some bash deployment here /usr/local/uberDeploy.sh ${targetHost.value} """ ) lazy val root: Project = Project("meme", file(".")) .settings( name := "hello", targetHost := "localhost", targetHost in remote := "snoopy" ) .settings(scriptSettings: _*) .settings(inConfig(remote)(scriptSettings) :_*) } 

Sets the expected result:

 > scriptContent [info] [info] # some bash deployment here [info] /usr/local/uberDeploy.sh localhost [info] > remote:scriptContent [info] [info] # some bash deployment here [info] /usr/local/uberDeploy.sh snoopy [info] > 
0
source

All Articles