SBT 配置扩展与默认设置

标签 sbt

如果我定义一个 SBT 配置

val MyConfig = config("my") 扩展测试

这与做的基本相同

val MyConfig = config("我的") val mySettings = inConfig(MyConfig)(Defaults.testSettings)

然后在构建定义中导入 mySettings ?

最佳答案

不,调用 extend 方法与调用 inConfig 不同。 extend 只是返回一个新的配置,并在前面加上 extendsConfigs 传入的配置,并且不会引入任何新设置。

当您将 MyConfig 添加到项目中时,它将成为作用域 key 解析路径的一部分:

val MyConfig = config("my") extend Test

val root = (project in file(".")).
  configs(MyConfig)

假设您在 sbt shell 中输入 my:test。由于在 my 配置下找不到 test 任务,因此它将遍历 extendsConfigs 并检查其下是否有可用的任务。它要命中的第一个是 Test,因为我们预先考虑了它。您可以通过运行 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

“提供者”表示它委托(delegate)给root/test:test。这种机制允许您共享一些设置但覆盖其他设置,但您仍然必须了解任务等范围内的设置的内部接线,因此这是一件棘手的事情。您可能已经知道,但我将链接到 Additional test configurations ,其中专门讨论了测试配置。

关于SBT 配置扩展与默认设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23162874/

相关文章:

scala - 在 SBT 上为每个任务加载不同的配置文件

scala - 在 sbt compile 上获取 Unresolved 依赖关系

scala - 如何解释这个 SBT DSL?

scala - SBT 无法解决 jersey-container-grizzly2-http 2.5.1 的依赖关系

java - 执行 jar 中资源包中包含的脚本

scala - spark-core 依赖项中的冲突。它是如何工作的?

eclipse - 如果我只想要顶级文件夹中的所有内容,有什么方法可以不混淆 sbt-eclipse? (2.2.0 与 0.12.4)

scala - 从SBT发布到本地Maven存储库

scala - 如何在运行测试之前运行任务

sbt - 如何在sbt 0.11.2中安装插件?