Find Dependency Tree Hierarchy In Gradle Based Java Project

Introduction

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.

  1. You may want to exclude a child library from a dependency
  2. You may want to exclude a child library from a dependency and include a different version of the same child library
  3. You may want to exclude a child library from all dependencies

The exclusion reason may be:

  1. Your project is not compatible with the version currently in use and want to use a specific version
  2. You found vulnerability with a version of the library is being used and want to upgrade
  3. You don’t need the specific library at all for your project and keeping it in the project may break the functionality

Prerequisites

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:

gradlew dependencies

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:

gradle dependency tree hierarchy

That’s one of the ways to find dependency tree hierarchy in gradle based Java project.

Leave a Reply

Your email address will not be published.