【问题标题】:Exclude test dependency resolution from `sbt compile`从`sbt compile`中排除测试依赖解析
【发布时间】:2014-07-18 09:21:38
【问题描述】:

在运行sbt compile 时,标记为test 的依赖项仍会被解析,即使它们稍后不会包含在编译中。似乎这应该只发生在test:compile 任务期间。有没有办法在compile 任务期间排除test 依赖项的解析和下载?

这是一个带有 org.mockito#mockito-all 依赖项的示例。我已将其声明为仅测试:

"org.mockito" %  "mockito-all" % "1.9.0" % "test"

但是,当(从我的本地 Ivy 缓存中清除它并)运行 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

【问题讨论】:

    标签: scala sbt ivy


    【解决方案1】:

    在 sbt 中,update 任务解决了所有配置的 all 依赖关系。 Sbt 利用了 Ivy,它促进了一个非常有趣的“配置”方面,能够同时分别解析不同的类路径。

    Sbt 不仅解析您的测试类路径,还解析运行时、scala 工具(编译器、scaladoc、repl)等等。

    请阅读:https://ant.apache.org/ivy/history/latest-milestone/terminology.html 了解有关 Ivy 设计的更多信息,这就是为什么 sbt 尝试一次为所有配置执行所有解析。

    【讨论】:

    • 所以,这听起来像是一个“不”:) 只是想知道,因为last update 显示confs: [compile, runtime, test, ... ]。不能更新吗?
    • 您可以修改 allDependencies 设置以删除您不想要的 conf 的所有依赖项。然后你将无法运行测试,直到你撤消它。
    • 啊,这听起来正是我在这种情况下所需要的。我会试试看。
    猜你喜欢
    • 2019-08-23
    • 2013-03-10
    • 2018-11-28
    • 2013-12-29
    • 2017-03-07
    • 1970-01-01
    • 1970-01-01
    • 2012-08-16
    • 2012-05-27
    相关资源
    最近更新 更多