脚本中的Gradle依赖层次结构

时间:2015-08-20 14:42:53

标签: gradle dependencies

我的目标是打印包含层次结构的gradle构建的依赖项。想法是以图形方式构建依赖图。我需要的信息与我输入gradle依赖项时的信息相同。

我怎么能做到这一点?当我创建自己的任务时,从哪里获取信息?

2 个答案:

答案 0 :(得分:2)

也许这就是你要找的东西:

project.configurations.compile.resolvedConfiguration.resolvedArtifacts.each {
 println it.name // << the artifact name
 println it.file // << the file reference
}

它来自How to retrieve a list of actual dependencies (including transitive deps) - Old Forum - Gradle Forums

答案 1 :(得分:1)

我只是一个傻瓜新手,所以也许你的问题有深度我不明白。你的意思是:

> gradle dependencies
:dependencies

------------------------------------------------------------
Root project
------------------------------------------------------------

archives - Configuration for archive artifacts.
No dependencies

compile - Compile classpath for source set 'main'.
\--- commons-collections:commons-collections:3.2

default - Configuration for default artifacts.
\--- commons-collections:commons-collections:3.2

runtime - Runtime classpath for source set 'main'.
\--- commons-collections:commons-collections:3.2

testCompile - Compile classpath for source set 'test'.
+--- commons-collections:commons-collections:3.2
\--- junit:junit:4.+ -> 4.12
     \--- org.hamcrest:hamcrest-core:1.3

testRuntime - Runtime classpath for source set 'test'.
+--- commons-collections:commons-collections:3.2
\--- junit:junit:4.+ -> 4.12
     \--- org.hamcrest:hamcrest-core:1.3

BUILD SUCCESSFUL

Total time: 4.47 secs

这是从仅包含这些直接依赖项的build.gradle文件创建的:

dependencies {
    compile group: 'commons-collections', name: 'commons-collections', version: '3.2'
    testCompile group: 'junit', name: 'junit', version: '4.+'
}