我有一个lazy val task = TaskKey[Unit]
以 alazy val setting = SettingKey[String]
作为输入的任务。我还有三个不同的独立配置范围(config("dev")
, config("stage")
, config("prod")
)和一个为每个配置范围build.sbt
指定不同值的文件( ... )。setting
setting in stage := "foo"
我希望task
使用配置范围前缀进行调用将使任务使用来自相应配置范围的值(例如 >dev:task
,将使任务使用setting
来自的值dev
,使用命令>stage:task
将使任务使用setting
来自stage
...的值)。但是,这似乎不起作用。
如何强制task
使用特定配置范围的设置?
构建.sbt:
setting := "default setting"
setting in stage := "stage setting"
setting in prod := "prod setting"
构建.scala:
import sbt._
import Keys._
object TaskBuild extends Build {
val setting = SettingKey[String]("setting", "a simple string setting")
val task = TaskKey[Unit]("task", "a simple task experiment")
val taskTask = task <<= setting map { s: String =>
println("Setting is: " + s)
}
lazy val dev = config("dev") describedAs("dev environment settings")
lazy val stage = config("stage") describedAs("stage environment settings")
lazy val prod = config("prod") describedAs("prod environment settings")
lazy val root = Project(
"project",
file("."),
settings = Defaults.defaultSettings ++ Seq(taskTask)
)
.configs(dev, stage, prod)
}