默认情况下run / aggregate
是false
:
sbt:root> inspect run / aggregate
[info] Setting: Boolean = false
[info] Description:
[info] Configures task aggregation.
[info] Provided by:
[info] Zero / run / aggregate
[info] Defined at:
[info] (sbt.Defaults.disableAggregate) Defaults.scala:1920
[info] Delegates:
[info] run / aggregate
[info] aggregate
[info] ThisBuild / run / aggregate
[info] ThisBuild / aggregate
[info] Zero / run / aggregate
[info] Global / aggregate
[info] Related:
[info] Global / aggregate
[info] Zero / run / aggregate
[info] Zero / consoleQuick / aggregate
[info] dependencyCheckPurge / aggregate
[info] refinedConsole / dependencyCheckUpdateOnly / aggregate
[info] refinedConsole / dependencyCheckAggregate / aggregate
[info] server / dependencyCheckListSettings / aggregate
[info] Zero / changedInputFiles / aggregate
[info] refinedConsole / dependencyCheckListSettings / aggregate
[info] refinedConsole / dependencyCheckPurge / aggregate
[info] ...
所以run
任务不会被聚合。
即使您将其设置为true
then 您也不太可能得到您想要的,因为聚合任务的顺序是未定义的。
创建任务依赖项是通过相互评估来完成的(正如@akauppi 在旧 SBT 语法中指出的那样):
lazy val project1 = (project in file("project1")
.settings(
Compile / run := (project2 / Compile / run).evaluated
)
现在,如果您还想调用run
on ,它会变得有点棘手project1
。
一种天真的方法是:
lazy val project1 = (project in file("project1")
.settings(
Compile / run := {
(project2 / Compile / run).evaluated
(project1 / Compile / run).evaluated
}
)
但不能保证这将首先运行 project2。
我还没有找到让它工作的方法。
我尝试使用:
(project2 / Compile / run).flatMap((project1 / Compile / run).toTask("").taskValue
但是你得到一个非法的动态引用错误。
我也试过:
Def.sequential((server / Compile / run).toTask(""), (Compile / run).toTask("")).value
但这只会在运行时给出未定义的设置错误。
♂️</p>