list gradle dependencies for all subprojects

Viewed 8732

I can query the dependency tree for a Gradle project with ./gradlew -q dependencies.

I can also run the query for the service subproject with ./gradlew service:dependencies.

How can I list the dependencies automatically for all subprojects from the command line without modifying the gradle.properties file?

Thank you in advance.

2 Answers

I believe there’s no built-in way in Gradle to achieve this (without adapting the build configuration) – unless you manually list the dependencies task for all subprojects as in:

./gradlew sub1:dependencies sub2:dependencies sub1:subsub:dependencies

However, if you need this feature often enough, then you could create a shell alias for it. Example in bash (e.g., put this in your ~/.bashrc file):

alias gradle-all-deps='./gradlew dependencies $(./gradlew -q projects \
    | grep -Fe ---\ Project \
    | sed -Ee "s/^.+--- Project '"'([^']+)'/\1:dependencies/"'")'

Then simply call gradle-all-deps from the root project directory.

Add following task in your root project's build.gradle file

subprojects {
    task allDeps(type: DependencyReportTask) {}
}

And execute the following command from the root project

./gradlew allDeps 

This will list dependencies of all subprojects.

Further if you want to narrow down the dependency graph on the basis of their type (compileClasspath, testRuntime ... ), please refer this

Related