1. Overview

A maven is a build tool which helps us to build an application. It will collect all library or its dependency from the maven repository behalf of us. But some time should require to know about a particular dependency which indicates which libraries are dependent on other libraries. Maven show dependency tree steps:

Step #1: Open a terminal and Go to the location where pom.xml file is available

Step #2: fire mvn dependency:tree command it will show maven dependency tree.

 1. mvn dependency:tree -Dverbose for more information about dependecy

2.  mvn dependency:tree -Dverbose -Dexcludes=commons-logging for exclude some dependency from tree

Here are more details about filter in depenecy tree: maven dependency tree filter document

2. Example

2.1 pom.xml

Here is maven pom which contains one dependency in the application:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.javadeveloperzone</groupId>
    <artifactId>maven-show-dependency-tree</artifactId>
    <version>1.0-SNAPSHOT</version>
    <description>How to check maven dependency tree</description>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <version>1.5.4.RELEASE</version>
        </dependency>
    </dependencies>

</project>

2.2 Command to check maven dependency

mvn dependency:tree

2.3 Output

Its output of dependency:tree where we can see the spring-boot-devtools dependency tree:

F:\extrawork\java-8\maven-show-dependency-tree>mvn dependency:tree
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building maven-show-dependency-tree 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ maven-show-dependency-tree ---
[INFO] com.javadeveloperzone:maven-show-dependency-tree:jar:1.0-SNAPSHOT
[INFO] \- org.springframework.boot:spring-boot-devtools:jar:1.5.4.RELEASE:compile
[INFO]    +- org.springframework.boot:spring-boot:jar:1.5.4.RELEASE:compile
[INFO]    |  +- org.springframework:spring-core:jar:4.3.9.RELEASE:compile
[INFO]    |  |  \- commons-logging:commons-logging:jar:1.2:compile
[INFO]    |  \- org.springframework:spring-context:jar:4.3.9.RELEASE:compile
[INFO]    |     +- org.springframework:spring-aop:jar:4.3.9.RELEASE:compile
[INFO]    |     +- org.springframework:spring-beans:jar:4.3.9.RELEASE:compile
[INFO]    |     \- org.springframework:spring-expression:jar:4.3.9.RELEASE:compile
[INFO]    \- org.springframework.boot:spring-boot-autoconfigure:jar:1.5.4.RELEASE:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.238 s
[INFO] Finished at: 2018-07-14T10:42:20+05:30
[INFO] Final Memory: 14M/232M
[INFO] ------------------------------------------------------------------------

3. References

Was this post helpful?
Let us know, if you liked the post. Only in this way, we can improve us.
Yes
No

Leave a Reply

Your email address will not be published. Required fields are marked *