覆盖自定义 SBT 任务的分叉设置

Overriding fork setting for custom SBT task

我正在 SBT 中执行自定义任务,它运行一些外部 Java class。我正在使用 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 来调整任务本身,但这也无济于事。

如何仅将 myCustomTaskfork 设置为 true

使用 fullRunTask,如 http://www.scala-sbt.org/0.13/docs/Faq.html#How+can+I+create+a+custom+run+task%2C+in+addition+to+%3F

中所述

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

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)
}