Maven dependency management in Eclipse

Introduction

Maven dependency management is easy in Eclipse IDE. One of the important features of Maven is dependency management. It handles the dependencies and their conflicts automatically under the cover.

Maven dependency management

You need to define all the required dependencies for the project explicitly in the POM.xml file. This information is read and maven decides which jars to load from the repositories automatically.

When a library X depends on another library Y ( X -> Y). Let’s say if the library Y is dependent on Z(Y -> Z ). We say that X is transitively dependent on library Z( X -> Z).

Dependency Properties

Each dependency we specify has several properties. To view the properties of a dependency, select it in the POM editor and click on Properties… button.

Group ID, Artifact ID, Version,Type,Scope,Optional or not etc.

Type can have values like a jar, war, ear, maven-plugin, etc.
The scope is like compile, runtime, provided, test, system, etc.

 

Dependency Properties

 

Dependency Hierarchy

 

Dependency Hierarchy

You can use the Maven POM editor to have a look at the dependency hierarchy tree. Maven has several features to control the transitive dependencies.

To manage your transitive dependency exclusions you can use the dependency hierarchy tree. You can exclude any transitive dependency artifact using the exclude option in the POM editor.

 

Dependency Hierarchy tree Eclipse

 

You can see that some artifact versions are omitted. This is due to dependency conflicts. Maven uses dependency mediation to determine what dependency artifact to be used when multiple versions are encountered.

You can find all the resolved dependencies on the right side pane of the dependency tree as shown above.