SBT 配置扩展与 DefaultSettings [英] SBT Config extend vs DefaultSettings
问题描述
如果我用
val MyConfig = config("my") extend Test
是不是和做的基本一样
val MyConfig = config("my")
val mySettings = inConfig(MyConfig)(Defaults.testSettings)
然后在构建定义中导入 mySettings ?
and then importing mySettings inside a build definition ?
推荐答案
不,调用 extend
方法与调用 inConfig
方法不同.extend
只是返回一个新的配置,传入的配置前面加上 extendsConfigs
,它不会引入任何新的设置.
No, calling extend
method is not the same thing as calling inConfig
. extend
just returns a new configuration with passed in configurations prepended extendsConfigs
, and it will not introduce any new settings.
当您将 MyConfig
添加到项目中时,它会成为作用域密钥解析路径的一部分:
When you add MyConfig
into the project, it becomes part of the scoped key resolution path:
val MyConfig = config("my") extend Test
val root = (project in file(".")).
configs(MyConfig)
假设您在 sbt shell 中键入 my:test
.由于在 my
配置下没有找到 test
任务,它会遍历 extendsConfigs
并检查任务下是否可用.它要命中的第一个是Test
,因为我们预先添加它.您可以通过运行 inspect my:test
:
Suppose you type my:test
in the sbt shell. Since test
task is not found under my
configuration, it will traverse extendsConfigs
and check if the tasks are available under them. The first one it's going to hit is Test
since we prepended it. You can check this by running inspect my:test
:
root> inspect my:test
[info] Task: Unit
[info] Description:
[info] Executes all tests.
[info] Provided by:
[info] {file:/Users/eugene/work/quick-test/sbt-so/}root/test:test
[info] Defined at:
[info] (sbt.Defaults) Defaults.scala:365
[info] Delegates:
[info] my:test
[info] test:test
[info] runtime:test
[info] compile:test
[info] *:test
[info] {.}/my:test
[info] {.}/test:test
[info] {.}/runtime:test
[info] {.}/compile:test
[info] {.}/*:test
[info] */my:test
[info] */test:test
[info] */runtime:test
[info] */compile:test
[info] */*:test
[info] Related:
[info] test:test
提供者"表示它委托给 root/test:test
.这种机制允许您共享一些设置但覆盖其他设置,但您仍然必须知道范围为任务等的设置的内部连接,所以这是一件棘手的事情.您可能已经知道,但我将链接到 附加测试配置,专门讨论测试配置.
"Provided by" says it delegated to root/test:test
. This mechanism allows you to share some of the settings but override others, but you still have to know the inner wiring of the settings scoped to tasks etc, so it's tricky business. You probably already know, but I'll link to Additional test configurations, which specifically discusses configurations for testing.
这篇关于SBT 配置扩展与 DefaultSettings的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!