gpt4 book ai didi

gradle - Gradle中的configuration.files和configuration.copy方法之间有什么区别?

转载 作者:行者123 更新时间:2023-12-03 04:34:12 25 4
gpt4 key购买 nike

在Gradle用户指南Chapter 23. Dependency Management中,示例显示Configuration.copy和Configuration.files方法之间的区别:

build.gradle

task copyVsFiles << {
configurations.sealife.copyRecursive { dep -> dep.name == 'orca' }
.each { file -> println file.name }
println()
configurations.sealife.files { dep -> dep.name == 'orca' }
.each { file -> println file.name }
}

Output of gradle -q copyVsFiles
> gradle -q copyVsFiles
orca-1.0.jar
seal-1.0.jar

orca-1.0.jar
seal-2.0.jar

以下说明使我感到困惑。我仍然不知道区别。谁能帮我这个 ?

最佳答案

问题的答案在Gradle API文档Chapter 23 Section 24中示例23.24之后的段落中。

请注意configuration.files方法如何返回密封 jar 的版本2。

In the example above, orca has a dependency on seal-1.0 whereas shark has a dependency onseal-2.0. The original configuration has therefore a version conflict which is resolved to the newer seal-2.0 version. The files method therefore returns seal-2.0 as a transitive dependency of orca. The copied configuration only has orca as a dependency and therefore there is no version conflict and seal-1.0 is returned as a transitive dependency.



要真正理解为什么会发生这种情况,请花一些时间查看 Gradle docs中的Configuration方法。

文件执行以下操作:

Resolves this configuration. This locates and downloads the files which make up this configuration. But only the resulting set of files belonging to the subset of dependencies specified by the dependencySpec is returned.



复制执行以下操作:

Creates a copy of this configuration that only contains the dependencies directly in this configuration (without contributions from superconfigurations). The new configuration will be in the UNRESOLVED state, but will retain all other attributes of this configuration except superconfigurations. Configuration.getHierarchy() for the copy will not include any superconfigurations.



这如何适用于文档示例? Configuration.files解析配置,如示例中的输出所示,该配置处理由 shark依赖的 seal-2.0.jar引入的版本冲突。 Configuration.copy创建配置的副本,并且尚未解析,这意味着它还没有版本冲突。

关于gradle - Gradle中的configuration.files和configuration.copy方法之间有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35391238/

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