Junior — Middle
How can you eliminate dependency on a library in the Maven build system?
sobes.tech AI
Answer from AI
In Maven, to resolve a dependency, you can use the <exclusions> element in the dependency description. This allows you to exclude transitive dependencies that come along with the main library.
For example, how to exclude a dependency inside pom.xml:
<dependency>
<groupId>com.example</groupId>
<artifactId>some-library</artifactId>
<version>1.0.0</version>
<exclusions>
<exclusion>
<groupId>com.unwanted</groupId>
<artifactId>unwanted-library</artifactId>
</exclusion>
</exclusions>
</dependency>
Thus, unwanted-library will not be added to the project, even though it is a dependency of some-library.
If you want to completely remove a dependency from the project, you can simply delete or comment out the corresponding <dependency> block in pom.xml.