5
如何聲明2個自定義設置,例如A和B,在Global
配置範圍中定義B,其內容依賴於A,在幾個配置範圍中對A定義不同以這樣的方式,即使B只定義一次,每個配置中B的結果值是不同的?如何依賴於「當前」配置中的設置
請考慮下面的例子targetHost
,在remote
定義不同於其他的配置,並根據其scriptContent
:
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}
"""
)
}
我想scriptContent
有兩種配置範圍不同的值,但由於它取決於就在Global
範圍targetHost
其價值始終是相同的:
> 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]
而我想獲取以下信息:
> 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]
我猜你需要明確指定任務的範圍。例如,在兩個範圍內實現兩個'scriptContent',一個是'targetHost in remote',另一個是簡單的'targetHost'。 – marios