Scala SBT中的顺序输入任务

Scala SBT中的顺序输入任务,scala,properties,sbt,sequential,sbt-assembly,Scala,Properties,Sbt,Sequential,Sbt Assembly,我正在尝试编写一个SBT任务,可以这样使用: > deploy key1=value1 key2=value2 ... val config = inputKey[Unit] ( "Set configuration options before deployment.") val deploy = inputKey[Unit]( "assemble fat .jar with configuration options") val defaultProperties = set

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

> deploy key1=value1 key2=value2 ...
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),
    ...)
是否有以下情况:

  • 读取默认属性文件
  • 将已解析的键和值添加到properties对象
  • 将新属性对象写入resources/config.properties
  • sbt程序集
  • 将默认属性写入resources/config.properties
  • 我一直试图用
    Def.sequential
    实现它,但我似乎找不到一种方法将它与
    inputKey
    结合使用。我的
    build.sbt
    如下所示:

    > deploy key1=value1 key2=value2 ...
    
    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),
        ...)
    
    val config=inputKey[单位](
    “在部署之前设置配置选项。”)
    val部署=输入键[单位](
    “使用配置选项组装fat.jar”)
    val defaultProperties=settingKey[Properties](
    “默认应用程序属性。”)
    val propertiesPath=settingKey[文件](“config.properties的路径”)
    val writeDefaultProperties=taskKey[Unit](“写入默认属性文件”)
    val解析器=((“”>StringBasic)
    部署配置
    .setProperty(选项1、选项2))
    IO.write(deployConfig,“,路径)
    },
    writeDefaultProperties:={
    val default=defaultProperties.value
    val path=propertiesPath.value
    IO.write(默认值,“,路径)
    },
    部署:=Def.sequential(
    config.parsed,//未编译
    装配
    writeDefaultProperties),
    ...)
    
    我是否可以使
    Def.sequential
    与输入键一起工作,或者我是否需要执行更复杂的操作?

    请参阅。它以
    scalastyle
    为例:

      (scalastyle in Compile).toTask("")
    
    看。它以
    scalastyle
    为例:

      (scalastyle in Compile).toTask("")