SBT中的顺序输入任务

时间:2016-04-08 12:14:50

标签: scala properties sbt sequential sbt-assembly

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

> deploy key1=value1 key2=value2 ...

并执行以下操作:

  1. 读取默认属性文件
  2. 将已解析的键和值添加到属性对象
  3. 将新属性对象写入resources / config.properties
  4. 使用sbt-assembly
  5. 打包一个胖.jar
  6. 将默认属性写入resources / config.properties
  7. 我一直试图用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使用输入键,还是需要做更多涉及的事情呢?

1 个答案:

答案 0 :(得分:0)

Defining a sequential task with Def.sequential。它使用scalastyle作为示例:

  (scalastyle in Compile).toTask("")