Maven – Display project dependency

In Maven, you can use mvn dependency:tree to display the project dependencies in tree format.

1. Maven Project

Review a simple Maven project, declared Spring and logback dependencies.

pom.xml

	<properties>
		<spring.version>4.1.6.RELEASE</spring.version>
		<logback.version>1.1.3</logback.version>
		<jcl.slf4j.version>1.7.12</jcl.slf4j.version>
	</properties>

	<dependencies>

	  <dependency>
		<groupId>org.springframework</groupId>
		<artifactId>spring-core</artifactId>
		<version>${spring.version}</version>
		<exclusions>
		  <exclusion>
			<groupId>commons-logging</groupId>
			<artifactId>commons-logging</artifactId>
		  </exclusion>
		</exclusions>
	  </dependency>

	  <dependency>
		<groupId>org.springframework</groupId>
		<artifactId>spring-webmvc</artifactId>
		<version>${spring.version}</version>
	  </dependency>

	  <dependency>
		<groupId>org.slf4j</groupId>
		<artifactId>jcl-over-slf4j</artifactId>
		<version>${jcl.slf4j.version}</version>
	  </dependency>

	  <dependency>
		<groupId>ch.qos.logback</groupId>
		<artifactId>logback-classic</artifactId>
		<version>${logback.version}</version>
	  </dependency>

	</dependencies>

2. mvn dependency:tree

Example to display above project dependencies.

Terminal

$ mvn dependency:tree

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building {Project Name}
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ spring-mvc-logback ---
[INFO] com.mkyong.common:spring-mvc-logback:war:1.0-SNAPSHOT
[INFO] +- org.springframework:spring-core:jar:4.1.6.RELEASE:compile
[INFO] +- org.springframework:spring-webmvc:jar:4.1.6.RELEASE:compile
[INFO] |  +- org.springframework:spring-beans:jar:4.1.6.RELEASE:compile
[INFO] |  +- org.springframework:spring-context:jar:4.1.6.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-aop:jar:4.1.6.RELEASE:compile
[INFO] |  |     \- aopalliance:aopalliance:jar:1.0:compile
[INFO] |  +- org.springframework:spring-expression:jar:4.1.6.RELEASE:compile
[INFO] |  \- org.springframework:spring-web:jar:4.1.6.RELEASE:compile
[INFO] +- org.slf4j:jcl-over-slf4j:jar:1.7.12:compile
[INFO] |  \- org.slf4j:slf4j-api:jar:1.7.12:compile
[INFO] +- ch.qos.logback:logback-classic:jar:1.1.3:compile
[INFO] |  \- ch.qos.logback:logback-core:jar:1.1.3:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.937 s
[INFO] Finished at: 2015-06-19T19:17:54+08:00
[INFO] Final Memory: 13M/308M
[INFO] ------------------------------------------------------------------------

Done.

Note
Visit Maven Dependency Plugin for more usages and examples.

About the Author

author image
mkyong
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

avatar
1 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
0 Comment authors
Maven and Junit example Recent comment authors
newest oldest most voted
trackback
Maven and Junit example

[…] Maven – Display project dependency […]