SBT中的顺序输入任务

Sequential input task in SBT

我正在尝试编写一个可以像这样使用的 SBT 任务:

> deploy key1=value1 key2=value2 ...

并执行以下操作:

  1. 读取默认属性文件
  2. 将解析的键和值添加到属性对象
  3. 将新属性对象写入 resources/config.properties
  4. sbt-assembly
  5. 打包了一个 fat .jar
  6. 将默认属性写入 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("")