sbt 依赖%“编译->编译;测试->测试”

时间:2021-05-05 23:34:04

标签: scala sbt

我一直试图理解“compile->compile;test->test”的用途,但在阅读 sbt 页面后我仍然不明白......

假设我在 build.sbt 中有这个

lazy val `api` = project.dependsOn(`domain` % "compile->compile;test->test")
...
lazy val `domain` = project...

如果我删除“compile->compile;test->test”有什么区别

lazy val `api` = project.dependsOn(`domain`)
...
lazy val `domain` = project...

如果我只输入“test->test”怎么办?还是“编译->编译”?

1 个答案:

答案 0 :(得分:4)

查看正在发生的事情的有用命令是

show api / Test / dependencyClasspath
show api / Compile / dependencyClasspath

这将显示确切的类路径。

<块引用>

如果我删除“compile->compile;test->test”

lazy val api = project.dependsOn(domain)

相当于

lazy val api = project.dependsOn(domain % "compile->compile")

表示 api / Compile 配置取决于 domain / Compile。如果您执行 show api / Test / dependencyClasspath ,那么您应该会看到 domain 的测试类路径不存在。

<块引用>

如果我只输入“test->test”怎么办?

lazy val api = project.dependsOn(domain % "test->test")

意味着 api / Test 依赖于 domain / Test 并且执行 show api / Test / dependencyClasspath 应该显示 domaintest 类路径存在。但是,执行 show api / Compile / dependencyClasspath 应该会显示 domaincompile 类路径不存在。

因此,如果您希望 api / Test 依赖于 domain / Test,而 api / Compile 依赖于 domain / Compile,那么您必须指定

lazy val api = project.dependsOn(domain % "compile->compile;test->test")