我想你只是对解释的第二部分中对差异范围的引用有点困惑。让我们明确地写下示例中的所有作用域:
ThisBuild / Zero / Zero / scalacOptions += "-Ywarn-unused-import"
lazy val projD = (project in file("d"))
.settings(
test := { println((Compile / console / scalacOptions).value) }
)
projD / Zero / console / scalacOptions -= "-Ywarn-unused-import"
projD / Compile / Zero / scalacOptions := (projD / Zero / Zero / scalacOptions).value
我必须去掉这两个设置,才能参考
projD
,但除此之外,它的定义是相同的。
从第一部分开始你就明白了
projD / Compile / Zero / scalacOptions
赢得
projD / Zero / console / scalacOptions
和
ThisBuild / ...
.
现在让我们看看它的价值,并在我们的任务中使用它。但它的价值是什么?指的是
projD / Zero / Zero / scalacOptions
没有明确定义。所以我们需要为它找到一个代表。目前我们还没有与
projD / Compile
和
projD / console
范围内唯一合适的键在范围内
ThisBuild / Zero / Zero
.
我试着在这里举例说明
/ scalacOptions
要节省空间,请执行以下操作:
projD / Compile / console // the one we need in the task
projD / Zero / console // could be applied by rule 3, but looses to the next one:
projD / Compile / Zero // applies by rule 2 (task scope delegation), defined with next one:
projD / Zero / Zero // not defined explicitly, so is delegated:
ThisBuild / Zero / Zero // applies by rule 4 (project scope delegation)