SBT中的顺序输入任务
Sequential input task in SBT
我正在尝试编写一个可以像这样使用的 SBT 任务:
> deploy key1=value1 key2=value2 ...
并执行以下操作:
- 读取默认属性文件
- 将解析的键和值添加到属性对象
- 将新属性对象写入 resources/config.properties
- 用
sbt-assembly
打包了一个 fat .jar
- 将默认属性写入 resources/config.properties
我一直在尝试用 Def.sequential
来实现它,但我似乎找不到用 inputKey
来使用它的方法。我的build.sbt
看起来像这样:
val config = inputKey[Unit] (
"Set configuration options before deployment.")
val deploy = inputKey[Unit](
"assemble fat .jar with configuration options")
val defaultProperties = settingKey[Properties](
"default application properties.")
val propertiesPath = settingKey[File]("path to config.properties")
val writeDefaultProperties = taskKey[Unit]("write default properties file.")
val parser = (((' ' ~> StringBasic) <~ '=') ~ StringBasic).+
lazy val root = (project in file("."))
.settings(
propertiesPath := {
val base = (resourceDirectory in Compile).value
base / "config.properties"
},
defaultProperties := {
val path = propertiesPath.value
val defaultConfig = new Properties
IO.load(defaultConfig, path)
defaultConfig
},
config := {
val path = propertiesPath.value
val defaultConfig = defaultProperties.value
val options = parser.parsed
val deployConfig = new Properties
deployConfig.putAll(defaultConfig)
options.foreach(option =>
deployConfig
.setProperty(option._1, option._2))
IO.write(deployConfig, "", path)
},
writeDefaultProperties := {
val default = defaultProperties.value
val path = propertiesPath.value
IO.write(default, "", path)
},
deploy := Def.sequential(
config.parsed, // does not compile
assembly,
writeDefaultProperties),
...)
我可以Def.sequential
使用输入键,还是我需要做一些更复杂的事情?
参见Defining a sequential task with Def.sequential。以scalastyle
为例:
(scalastyle in Compile).toTask("")
我正在尝试编写一个可以像这样使用的 SBT 任务:
> deploy key1=value1 key2=value2 ...
并执行以下操作:
- 读取默认属性文件
- 将解析的键和值添加到属性对象
- 将新属性对象写入 resources/config.properties
- 用
sbt-assembly
打包了一个 fat .jar
- 将默认属性写入 resources/config.properties
我一直在尝试用 Def.sequential
来实现它,但我似乎找不到用 inputKey
来使用它的方法。我的build.sbt
看起来像这样:
val config = inputKey[Unit] (
"Set configuration options before deployment.")
val deploy = inputKey[Unit](
"assemble fat .jar with configuration options")
val defaultProperties = settingKey[Properties](
"default application properties.")
val propertiesPath = settingKey[File]("path to config.properties")
val writeDefaultProperties = taskKey[Unit]("write default properties file.")
val parser = (((' ' ~> StringBasic) <~ '=') ~ StringBasic).+
lazy val root = (project in file("."))
.settings(
propertiesPath := {
val base = (resourceDirectory in Compile).value
base / "config.properties"
},
defaultProperties := {
val path = propertiesPath.value
val defaultConfig = new Properties
IO.load(defaultConfig, path)
defaultConfig
},
config := {
val path = propertiesPath.value
val defaultConfig = defaultProperties.value
val options = parser.parsed
val deployConfig = new Properties
deployConfig.putAll(defaultConfig)
options.foreach(option =>
deployConfig
.setProperty(option._1, option._2))
IO.write(deployConfig, "", path)
},
writeDefaultProperties := {
val default = defaultProperties.value
val path = propertiesPath.value
IO.write(default, "", path)
},
deploy := Def.sequential(
config.parsed, // does not compile
assembly,
writeDefaultProperties),
...)
我可以Def.sequential
使用输入键,还是我需要做一些更复杂的事情?
参见Defining a sequential task with Def.sequential。以scalastyle
为例:
(scalastyle in Compile).toTask("")