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?
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. Required fields are marked *