如何限制对 sbt 运行 和 sbt test 任务的更改?
How to limit changes to `sbt run` and `sbt test` tasks?
我对 sbt
工具感到困惑。我想定义两个 Java 选项,一个用于 sbt run
目标,另一个用于 sbt test
目标。这些选项需要分叉 VM,我不希望其他命令(例如 compile
、update
)发生这种情况。
如何在build.sbt
中优雅地定义这个?
Compile
东西的作用是什么? Test
呢?
- 如何只声明一次
fork
,以便它同时适用于 sbt run
和 sbt test
?
我已经使用 sbt
几年了,现在。阅读文档。像这样的事情仍然逃避我。 感叹
fork in run := true
javaOptions in (Compile,run) ++= Seq(
"-Dconfig.file=conf/debug.conf"
)
fork in test := true
javaOptions in (Test,test) ++= Seq(
"-Dconfig.file=conf/debug-test.conf"
)
使用 sbt
0.13.8
假设你想指定你只想在 sbt run
上 fork() 而不是在 run
的其他执行上(例如,在 sbt test:run
上)那么你需要使用配置范围与任务一起。即:
fork in (Compile,run) := true
如果您有以下情况:
fork in run := true
它将分叉所有 运行 任务,包括 test:run
等
现在,如果你有这个:
fork := true
它将 fork() 所有范围内的所有可 fork 任务。
回到您的问题,您可以将 (Compile, 运行) 和 (Test, 运行) 等视为 (Configuration,task)
范围的实例。当您想要将特定设置的范围缩小到特定配置的任务时,您应该使用此构造:编译、运行、测试或您可能拥有的任何自定义配置。
在你的 .sbt
文件中,我认为正确的做法是:
fork in (Compile,run) := true
javaOptions in (Compile,run) ++= Seq(
"-Dconfig.file=conf/debug.conf"
)
fork in (Test,test) := true
javaOptions in (Test,test) ++= Seq(
"-Dconfig.file=conf/debug-test.conf"
)
我对 sbt
工具感到困惑。我想定义两个 Java 选项,一个用于 sbt run
目标,另一个用于 sbt test
目标。这些选项需要分叉 VM,我不希望其他命令(例如 compile
、update
)发生这种情况。
如何在build.sbt
中优雅地定义这个?
Compile
东西的作用是什么?Test
呢?- 如何只声明一次
fork
,以便它同时适用于sbt run
和sbt test
?
我已经使用 sbt
几年了,现在。阅读文档。像这样的事情仍然逃避我。 感叹
fork in run := true
javaOptions in (Compile,run) ++= Seq(
"-Dconfig.file=conf/debug.conf"
)
fork in test := true
javaOptions in (Test,test) ++= Seq(
"-Dconfig.file=conf/debug-test.conf"
)
使用 sbt
0.13.8
假设你想指定你只想在 sbt run
上 fork() 而不是在 run
的其他执行上(例如,在 sbt test:run
上)那么你需要使用配置范围与任务一起。即:
fork in (Compile,run) := true
如果您有以下情况:
fork in run := true
它将分叉所有 运行 任务,包括 test:run
等
现在,如果你有这个:
fork := true
它将 fork() 所有范围内的所有可 fork 任务。
回到您的问题,您可以将 (Compile, 运行) 和 (Test, 运行) 等视为 (Configuration,task)
范围的实例。当您想要将特定设置的范围缩小到特定配置的任务时,您应该使用此构造:编译、运行、测试或您可能拥有的任何自定义配置。
在你的 .sbt
文件中,我认为正确的做法是:
fork in (Compile,run) := true
javaOptions in (Compile,run) ++= Seq(
"-Dconfig.file=conf/debug.conf"
)
fork in (Test,test) := true
javaOptions in (Test,test) ++= Seq(
"-Dconfig.file=conf/debug-test.conf"
)