【问题标题】:Overriding fork setting for custom SBT task覆盖自定义 SBT 任务的分叉设置
【发布时间】:2015-07-31 23:29:58
【问题描述】:

我正在 SBT 中实现一个自定义任务,它运行一些外部 Java 类。我正在使用runner 任务来执行此操作。

myCustomTask := {
  val mainClass: String = ???
  val classpath: Seq[File] = ???
  val options: Seq[String] = ???
  runner.value.run(mainClass, classpath, options, streams.value.log)
}

我想配置此任务,使其在单独的 JVM 中运行。通常,这是使用fork 选项配置的,然后由runner 任务引用。

我只想为我的自定义任务配置分叉。我试过这样做:

fork in myCustomTask := true

但它不起作用。 runner 任务仍然获得不变的 fork 值。

我还尝试通过使用(runner in myCustomTask) 而不是仅使用runner 来调整任务本身,但这也无济于事。

如何将fork 设置为true 仅用于myCustomTask

【问题讨论】:

    标签: scala sbt


    【解决方案1】:

    我终于解决了这样的问题:

    fork in myCustomTask := true,
    myCustomTask := {
      val mainClass: String = ???
      val classpath: Seq[File] = ???
      val options: Seq[String] = ???
      val runner = initScoped(myCustomTask.scopedKey, Defaults.runnerInit).value
      runner.run(mainClass, classpath, options, streams.value.log)
    }
    

    【讨论】:

      【解决方案2】:

      【讨论】:

      • 这很好,但我不喜欢它只适用于返回 Unit 的任务。
      • 它实际上不允许你配置 ForkOptions。
      猜你喜欢
      • 1970-01-01
      • 2019-01-23
      • 2021-10-31
      • 1970-01-01
      • 2017-08-12
      • 2017-11-26
      • 2016-04-22
      • 2018-04-09
      • 2014-06-03
      相关资源
      最近更新 更多