Monday, 20 April 2020

SE - 62 - How to exclude a dependency in Maven and how to make a dependency optional ?

Sometimes there is requirement to make a dependency optional or exclude that particular dependency. We can achieve it by manually deleting it from .m2 folder . There is another efficient way to do it through pom.xml file by using particular tags. Lets see how :


1) To make a dependency Optional :

  1. <dependencies>
  2. <dependency>
  3. <groupId>org.seleniumhq</groupId>
  4. <artifactId>selenium</artifactId>
  5. <version>1.0</version>
  6. <optional>true</optional> <!-- we set value as true or false only -->
  7. </dependency>
  8. </dependencies>
Here we are simply using a optional tag in particular dependency and set the optional tag either as true or false.

2) To exclude a particular dependency :
  1. <exclusions>
  2. <exclusion>
  3. <groupId>org.seleniumhq</groupId>
  4. <artifactId>selenium</artifactId>
  5. </exclusion>
  6. </exclusions>
Here we can add the dependencies that can be excluded from the dependency by using this

No comments:

Post a Comment