How to exclude dependency in maven?

By | November 21, 2020

In this post, We will learn How to exclude dependency or specific version dependency in maven?

Whenever we have transitive dependencies in our project, there we may get version mismatch issues between the dependencies of the artifacts or mismatch in versions of our project artifact and the deployment platform’s artifact.

That can be done by excluding dependencies and breaking the transitive dependency by using the <exclusion> tag.

The unwanted dependencies can be excluded from the project’s classpath when maven resolves the transitive dependencies by using the exclusion technique. The excluded dependencies or artifacts will not be added to your project’s classpath based on the way dependencies are excluded within the <exclusion> tag.

That may be done for problematic jars and jars that are of older versions and not compatible with our project’s java version or jars that are not compatible with any other dependencies in our project.

We can have multiple transitive dependencies can be excluded by using the <exclusion> tag for each of the dependencies we want to exclude and placing all these exclusion tags inside the <exclusions> tag in pom.xml.

Let us understand how we can exclude the transitive dependency with the help of an example.

In this example, we are going to exclude cglib from spring

Complete pom.xml

That’s all about How to exclude dependency in maven?

You May Also Like:

How to create a multi-module project using maven?
How to Fix missing src/main/java & src/test/java folders in the Eclipse Maven web Project?
How to create user-defined properties in Maven?
What is the maven local repository location & how to change it?
How to add or update the maven settings.xml file in eclipse?
Importing maven remote Archetype Catalogs in eclipse ?
What is POM in the maven Project?
What is Super POM in Maven Project?
Understanding the purpose of Maven Plugin
Compiling the Maven project with different JDK versions? 
Understanding of settings.xml in maven
How to enable a proxy setting in Maven?
Maven Dependency Scopes
How to generate javadoc in the maven Project
How to add local jar files to a Maven project?
How to convert an existing Java Project to Maven in Eclipse?
How to exclude dependency in maven?
Managing External Dependencies in maven
Understanding of Maven Repositories
What is an archetype in Maven?
Snapshot Vs Version in maven
Apache Maven – Profiles

If you have any feedback or suggestion please feel free to drop in below comment box.

Leave a Reply

Your email address will not be published.