maven exclude dependency

In Maven, you can exclude a transitive dependency (i.e., a dependency of a dependency) that is brought in by a direct dependency by using the exclusions element. Here's how you can exclude a transitive dependency in your pom.xml file:

<dependency>
  <groupId>my.group.id</groupId>
  <artifactId>my-artifact</artifactId>
  <version>1.0.0</version>
  <exclusions>
    <exclusion>
      <groupId>other.group.id</groupId>
      <artifactId>undesired-artifact</artifactId>
    </exclusion>
  </exclusions>
</dependency>
Sou‮‬rce:www.theitroad.com

In this example, the my-artifact dependency has a transitive dependency on undesired-artifact, but we want to exclude it from our project. By adding the exclusions element and specifying the groupId and artifactId of the undesired artifact, we can exclude it from our project.

Note that if you exclude a transitive dependency, you should make sure that your direct dependency doesn't actually need that dependency to function properly. In some cases, excluding a transitive dependency can cause problems in your application.