In this example, I am going to show you how to find dependency hierarchy using gradle build tool in your Java based projects. Your Spring Boot projects might be using gradle build tool and you want to check what dependencies are used in your project.
You can easily find what libraries are used in your project by looking into the content of the build.gradle script, but you may not understand what actual dependent libraries are being used in your project. You can find all related libraries or jar files in the IDE or tool for a particular application or project, but again it is not actually visible which library is dependent on which library.
Why do you need to find the dependent libraries?
There are number of reasons for which you may need to find the dependency hierarchy for your project libraries.
- You may want to exclude a child library from a dependency
- You may want to exclude a child library from a dependency and include a different version of the same child library
- You may want to exclude a child library from all dependencies
The exclusion reason may be:
- Your project is not compatible with the version currently in use and want to use a specific version
- You found vulnerability with a version of the library is being used and want to upgrade
- You don’t need the specific library at all for your project and keeping it in the project may break the functionality
Gradle, Java, Spring/Spring Boot (depends on project nature)
Find Dependency Hierarchy
Execute the following command on CLI to see the list of dependencies in hierarchical manner:
The above command will list dependencies in the CLI itself. To view better the list of dependencies in hierarchical tree, you can save it to a file, for example to a text file (dependencies.txt):
gradlew dependencies > dependencies.txt
For example, you will find dependencies in tree structure as shown in the below image:
That’s one of the ways to find dependency tree hierarchy in gradle based Java project.