Is it possible to use gradle to produce a tree of what depends on what?
I have a project and would like to find out all the dependencies so I may be able to prune it
If you want to visualize your dependencies in a graph you can use gradle-dependency-graph-generator plugin.
Generally the output of this plugin can be found in build/reports/dependency-graph directory and it contains three files (.dot|.png|.svg) if you are using the 0.5.0 version of the plugin.
Example of dependences graph in a real app (Chess Clock):
Note that you may need to do something like ./gradlew <module_directory>:<module_name>:dependencies
if the module has extra directory before reach its build.gradle. When in doubt, do ./gradlew tasks --all
to check the name.
I also found useful to run this:
./gradlew dI --dependency <your library>
This shows how are being dependencies resolved (dependencyInsight
) and help you debugging into where do you need to force or exclude libraries in your build.gradle
See: https://docs.gradle.org/current/userguide/tutorial_gradle_command_line.html
If you want all the dependencies in a single file at the end within two steps.
Add this to your build.gradle.kts
in the root of your project:
project.rootProject.allprojects {
apply(plugin="project-report")
this.task("allDependencies", DependencyReportTask::class) {
evaluationDependsOnChildren()
this.setRenderer(AsciiDependencyReportRenderer())
}
}
Then apply:
./gradlew allDependencies | grep '\-\-\-' | grep -Po '\w+.*$' | awk -F ' ' '{ print $1 }' | sort | grep -v '\{' | grep -v '\[' | uniq | grep '.\+:.\+:.\+'
This will give you all the dependencies in your project and sub-projects along with all the 3rd party dependencies.
If you want to get this done in a programmatic way, then you'll need a custom renderer of the dependencies - you can start by extending the AsciiDependencyReportRenderer
that prints an ascii graph of the dependencies by default.
In Android Studio
1) Open terminal and ensure you are at project's root folder.
2) Run ./gradlew app:dependencies
(if not using gradle wrapper, try gradle app:dependencies
)
Note that running ./gradle dependencies
will only give you dependency tree of project's root folder, so mentioning app in above manner, i.e. ./gradlew app:dependencies
is important.
For Android, type this in terminal
gradlew app:dependencies
It will list all the dependencies and the ones with newer versions for you to upgrade like
com.android.support:customtabs:26.1.0 -> 27.1.1 (*)