Maven - SPLessons

Maven Dependency Tree

Home > Lesson > Chapter 9
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

Maven Dependency Tree

Maven Dependency Tree

shape Introduction

Dependency management is the best feature of Maven. Maven Dependency Tree chapter explains about M2Eclipse Plug-in, Graph and how to prepare the Maven Dependency Tree.

shape Description

Maven reads all the POM files and many transitive dependencies with latest versions that need to be downloaded as per the project type. One should know from where these dependencies are coming from. Sometimes, conflicts occur between the dependencies. Suppose there are two dependencies like commons-logging and servlet-api, one has to be excluded. So, to remove the conflict, dependency:tree and dependency:resolve are the required goals to be given in the command prompt. Dependency Tree acts as a investigation tool to define the dependency by making a list of resolved dependencies. It searches and filters the required dependencies. There are two ways to accomplish the dependencies as outputs in projects, they are:

M2Eclipse plug-in

shape Description

To get the dependency as output, M2Eclipse plug-in should be used. Once plug-in is installed, users should open pom file and click on the Dependency hierarchy under tabs. All the JAR files being brought to the project are found on the left and the resolved list of dependencies that are going to be used in the project on the right of the window. In the above window, all the compiled and provided words are represented in brackets. Provided defines that the dependency will be used while compiling and executing the tests. Provided dependencies cannot be used in packaged files. Compile specifies the dependencies in JAR, and WAR files.

Graphs

shape Description

When a graph is prepared with dependencies, the top box is the main dependency and the remaining dependencies will be routed from the top most box. One can also select the required node to highlight the linked dependencies. The jar logo on the folders indicates that the artifact is from the Maven Repository.

Dependency Scope

shape Table

Dependency Scope
compile default
provided by JDK or a container at run-time
runtime not required for compilation
test Used only during tests
system provided locally
import Available only in Maven 2.0.9 or later

Summary

shape Key Points

  • Maven Dependency Tree will help in resolving transitive dependencies.
  • M2Eclipse plug-in and GraphML can be used to filter out the dependencies.