在下面的build.sbt中,它包含一个根项目和一个子项目,我要添加一些简单的任务来打印一些文本作为对根项目和子项目的编译任务的依赖:
ThisBuild / scalaVersion := "2.12.6"
lazy val root = (project in file("."))
.settings(name := "sbt-task-test")
lazy val rootPrintTask = taskKey[Unit]("root print task")
rootPrintTask := {println("root")}
(root / Compile / compile) := (root / Compile / compile).dependsOn(rootPrintTask).value
lazy val sub = (project in file("sub"))
.settings(name := "sub")
lazy val subPrintTask = taskKey[Unit]("sub print task")
subPrintTask := {println("sub")}
(sub / Compile / compile) := (sub / Compile / compile).dependsOn(subPrintTask).value
和project / build.properties:
sbt.version = 1.2.1
编译根项目时,我的输出如下:
[IJ]sbt:sbt-task-test> root/Compile/compile
root
[success] Total time: 0 s, completed 21-Aug-2018 11:04:49
您可以看到rootPrintTask已执行并打印为“ root”
但是,在编译子项目时,不会执行subPrintTask,因此不会打印'sub':
[IJ]sbt:sbt-task-test> sub/Compile/compile
[success] Total time: 0 s, completed 21-Aug-2018 11:04:51
在检查两个编译任务时也会对此进行验证:
[IJ]sbt:sbt-task-test> inspect root/Compile/compile
[info] ...
[info] Dependencies:
[info] Compile / manipulateBytecode
[info] Compile / enableBinaryCompileAnalysis
[info] Compile / compileIncSetup
[info] rootPrintTask
[info] ...
[IJ]sbt:sbt-task-test> inspect sub/Compile/compile
[info] ...
[info] Dependencies:
[info] sub / Compile / manipulateBytecode
[info] sub / Compile / enableBinaryCompileAnalysis
[info] sub / Compile / compileIncSetup
[info] ...
这是预期的行为,还是sbt工具中的错误?
答案 0 :(得分:0)
您需要将static_cast<T*>(static_cast<void*>(addy)) == reinterpret_cast<T*>(addy)
设置移至sub / Compile / compile
项目的sub
:
.settings(...)
通常,如果您明确定义子项目,则不应在val sub = project
.settings(
subPrintTask := { println("sub") },
Compile / compile := (Compile / compile).dependsOn(subPrintTask).value,
)
的“无范围”空间中进行设置。