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

使用Gradle获取依赖项列表(而不是树),gradle,Gradle,我有一个具有复杂依赖关系的Gradle项目,我可以使用/gradlew模块名称: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

我有一个具有复杂依赖关系的Gradle项目,我可以使用
/gradlew模块名称: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 (*)
[...]
为了查看依赖项集是否更改,我想比较依赖项列表。换句话说,我想展平上面显示的树视图,这样我就可以专注于与传递包含无关的差异


有了Maven,我可以做
mvn依赖项:树
mvn依赖项:列表
。如何使用Gradle做到这一点?

我认为您不会找到一些Gradle核心任务来实现这一点(可能存在一些社区插件),但您可以编写自己的自定义
任务
以任何格式列出依赖项(文本、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")}
            }
        }
    }
}