gpt4 book ai didi

gradle - 使用Gradle获取依赖项列表(不是树)

转载 作者:行者123 更新时间:2023-12-03 05:03:57 27 4
gpt4 key购买 nike

我有一个具有复杂依赖项的Gradle项目,可以使用./gradlew module-name:dependencies看到它:

[...]
testRuntimeClasspath - Runtime classpath of source set 'test'.
+--- org.apache.logging.log4j:log4j-core -> 2.11.0
| \--- org.apache.logging.log4j:log4j-api:2.11.0
+--- com.google.guava:guava -> 20.0
+--- project :xxx
| +--- org.springframework:spring-tx -> 5.1.7.RELEASE
| | +--- org.springframework:spring-beans:5.1.7.RELEASE
| | | \--- org.springframework:spring-core:5.1.7.RELEASE
| | | \--- org.springframework:spring-jcl:5.1.7.RELEASE
| | \--- org.springframework:spring-core:5.1.7.RELEASE (*)
| +--- org.springframework:spring-context -> 5.1.7.RELEASE
| | +--- org.springframework:spring-aop:5.1.7.RELEASE
| | | +--- org.springframework:spring-beans:5.1.7.RELEASE (*)
| | | \--- org.springframework:spring-core:5.1.7.RELEASE (*)
| | +--- org.springframework:spring-beans:5.1.7.RELEASE (*)
| | +--- org.springframework:spring-core:5.1.7.RELEASE (*)
| | \--- org.springframework:spring-expression:5.1.7.RELEASE
| | \--- org.springframework:spring-core:5.1.7.RELEASE (*)
[...]
当我排除嵌套依赖项并明确包括它们时,结果可能如下所示:
[...]
testRuntimeClasspath - Runtime classpath of source set 'test'.
+--- org.apache.logging.log4j:log4j-core -> 2.11.0
| \--- org.apache.logging.log4j:log4j-api:2.11.0
+--- com.google.guava:guava -> 20.0
+--- project :xxx
| +--- org.springframework:spring-context -> 5.1.7.RELEASE
| | +--- org.springframework:spring-aop:5.1.7.RELEASE
| | | +--- org.springframework:spring-beans:5.1.7.RELEASE (*)
| | | \--- org.springframework:spring-core:5.1.7.RELEASE (*)
| | +--- org.springframework:spring-beans:5.1.7.RELEASE (*)
| | +--- org.springframework:spring-core:5.1.7.RELEASE (*)
| | \--- org.springframework:spring-expression:5.1.7.RELEASE
| | \--- org.springframework:spring-core:5.1.7.RELEASE (*)
+--- org.springframework:spring-tx -> 5.1.7.RELEASE
| +--- org.springframework:spring-beans:5.1.7.RELEASE
| | \--- org.springframework:spring-core:5.1.7.RELEASE
| | \--- org.springframework:spring-jcl:5.1.7.RELEASE
| \--- org.springframework:spring-core:5.1.7.RELEASE (*)
[...]
为了查看依赖项集是否已更改,我想比较依赖项列表。换句话说,我想展平上面显示的树状 View ,以便我可以专注于与传递包含无关的差异。
使用Maven,我可以执行 mvn dependency:treemvn dependency:list。如何使用Gradle做到这一点?

最佳答案

我认为您不会找到实现这一目标的Gradle核心任务(也许存在一些社区插件),但是您可以编写自己的自定义task以列出想要的任何格式的依赖项(文本,csv,...)

task dependencyList() {
doLast() {
configurations.each { configuration ->
if (configuration.isCanBeResolved()){
println("Configuration $configuration.name ================================")
def files = configuration.resolvedConfiguration.getFiles().sort()
files.forEach{ f -> println(" dep: $f.name")}
}
}
}
}

关于gradle - 使用Gradle获取依赖项列表(不是树),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62658061/

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