我的目標是打印包含層次結構的gradle構建的依賴關係。這個想法是以圖形方式構建一個依賴關係圖。我需要的信息將與我輸入gradle依賴關係時相同。腳本中的Gradle依賴關係層次結構
我該如何實現這一目標?當我創建自己的任務時,我從哪裏獲得信息?
我的目標是打印包含層次結構的gradle構建的依賴關係。這個想法是以圖形方式構建一個依賴關係圖。我需要的信息將與我輸入gradle依賴關係時相同。腳本中的Gradle依賴關係層次結構
我該如何實現這一目標?當我創建自己的任務時,我從哪裏獲得信息?
我只是一個gradle新手,所以也許有你的問題的深度,我沒有看到。你的意思是:
> 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.+'
}
也許這是你在找什麼:
project.configurations.compile.resolvedConfiguration.resolvedArtifacts.each {
println it.name // << the artifact name
println it.file // << the file reference
}
是的,這是Gradle爲我提供的。但是我想影響輸出。生成一個.dot圖。因此,我需要完成一項任務,例如「depentenciesAsDOTGraph」,它遍歷所有這些依賴關係並打印圖形。然而,我不知道我需要訪問哪些對象來遍歷依賴關係的層次結構和打印文件... – user1587852
Perl是你的朋友,如果你想解析'gradle dependencies'的輸出! :-) –