gpt4 book ai didi

Gradle trump 提供了Compile的排除?

转载 作者:行者123 更新时间:2023-12-03 03:10:14 26 4
gpt4 key购买 nike

我有一个项目,我想使用提供的编译来避免拉动它的库。但是,这会阻止我拉入我确实需要的另一个项目的库。文档说:如果您不想要这种传递行为,只需声明您提供的依赖项,但它没有给出如何执行此操作的示例。

这基本上是我的依赖项的样子:

dependencies {
compile(project(':common'))
providedCompile(project(':projA')) // <-- also depends on :common
}

我的 war 文件正确地从 projA 中排除了所有可传递的库,但我需要为 common.jar 胜过它,但我不知道如何做到这一点。但文档似乎表明这是可能的......

编辑:这是一个似乎有效的hacky配置。 “projA”的行组合为我提供了 projA.jar 作为依赖项,但不是它的子项。由于“common”是一个编译依赖项,而“projA”只被认为是在运行时提供的,由于编译时的依赖关系,我仍然得到了common.jar。我不确定它是否应该以这种方式工作,但它引发了我需要的 war 。
dependencies {
compile(project(':projA')) { transitive = false }
providedRuntime(project(':projA')) { transitive = false }
compile(project(':common'))
}

最佳答案

If you don't want this transitive behavior, simply declare your provided dependencies



这意味着如果您不想声明 projA 的所有依赖项,则需要将它们一一列出。

来自 Gradle 1.8 用户指南 '26.4。依赖管理'

The War plugin adds two dependency configurations: providedCompile and providedRuntime. Those configurations have the same scope as the respective compile and runtime configurations, except that they are not added to the WAR archive. It is important to note that those provided configurations work transitively. Let's say you add commons-httpclient:commons-httpclient:3.0 to any of the provided configurations. This dependency has a dependency on commons-codec. This means neither httpclient nor commons-codec is added to your WAR, even if commons-codec were an explicit dependency of your compile configuration. If you don't want this transitive behavior, simply declare your provided dependencies like commons-httpclient:commons-httpclient:3.0@jar.

关于Gradle trump 提供了Compile的排除?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19869889/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com