【问题标题】:Moving transitive dependency from implementation to testImplementation将传递依赖从 implementation 转移到 testImplementation
【发布时间】:2022-10-06 04:58:29
【问题描述】:

我的依赖项很少,它们对测试具有相同的传递依赖项,导致测试依赖项最终出现在我的“实现”中。

我可以以某种方式顺利地将所述依赖重定向到 \'testImplementation\' 还是我必须执行类似的操作:

implementation(A){exclude T}
implementation(B){exclude T}
implementation(C){exclude T}
testImplementation(T)
  • TA-C 正常运行所需的依赖项吗?换句话说,TA-C 的 API 的一部分吗?如果不是,则依赖项 A-C 不应将 T 声明为 api 依赖项,而是将其声明为 compileOnly 或使用 feature variants 以避免向消费者添加不必要的依赖项
  • 我无法控制 A-C,也不需要 T。
  • 您应该能够在配置级别排除 T(即对于所有 \'implementation\'),因此您不需要为每个将其拉入的单独实现依赖项排除它。

标签: gradle


【解决方案1】:

更好的一点是:

configurations {
  implementation {
    exclude(T)
  }
}
testImplementation(T)

然后,您不需要为每个可能将其引入的 implementation 依赖项显式排除 T

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-07-28
    • 2011-11-24
    • 2017-01-17
    • 2023-03-20
    • 2018-07-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多