运行时sbt compile,标记为的依赖项test仍会得到解析,即使它们稍后不会包含在编译中。似乎这应该只在test:compile任务期间发生。有没有办法test在compile任务期间排除依赖项的解析和下载?
这是一个具有org.mockito#mockito-all依赖关系的示例。我已将其声明为仅测试:
"org.mockito" % "mockito-all" % "1.9.0" % "test"
Run Code Online (Sandbox Code Playgroud)
但是,当(从我的本地常春藤缓存中清除它并)运行时sbt compile,它会被不必要地下载:
$ sbt compile
[info] Loading global plugins from /Users/rbrainard/.sbt/plugins
[info] Loading project definition from /Users/rbrainard/Development/spitball/project
[info] Set current project to spitball (in build file:/Users/rbrainard/Development/spitball/)
[info] Updating {file:/Users/rbrainard/Development/spitball/}spitball...
[info] Resolving org.mockito#mockito-all;1.9.0 ...
[info] downloading http://repo1.maven.org/maven2/org/mockito/mockito-all/1.9.0/mockito-all-1.9.0.jar ...
[info] [SUCCESSFUL ] org.mockito#mockito-all;1.9.0!mockito-all.jar (2075ms)
[info] Done updating.
[success] Total time: 7 s, completed May 28, 2014 4:51:20 PM
在 sbt 中,update任务解决所有配置的所有依赖关系。Sbt 利用 Ivy,它促进了一个非常有趣的“配置”方面,能够同时单独解析不同的类路径。
Sbt 不仅解析您的测试类路径,还解析运行时、scala 工具(编译器、scaladoc、repl)等。
请阅读: https: //ant.apache.org/ivy/history/latest-milestone/terminology.html了解有关 Ivy 设计的更多信息,这就是 sbt 尝试对所有配置同时进行所有解析的原因。