Reputation: 461
I am having a pom.xml with many dependency sections. Many of these dependency jars are having junit jar embedded in it, and hence I want to exclude it from the dependency of each jar, like below -
<dependency>
<groupId>abcd</groupId>
<artifactId>xxdd</artifactId>
<version>0.0.0.1</version>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
The problem is, for all dependency do I have to give this code section to exclude junit jar?? Is there a way to exclude globally from all the dependencies?
Thanks
Upvotes: 1
Views: 3746
Reputation: 349
<dependency>
<groupId>abcd</groupId>
<artifactId>xxdd</artifactId>
<version>0.0.0.1</version>
<scope>provided</scope>
</dependency>
You can make use of provided, this will be used for compilation but will not be used in packaging. More info on Dependency scope : https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html
You no need to specify for multiple dependencies, you can specify once and work is done.
Upvotes: 0
Reputation: 4413
You don't have to exclude junit, it is defined with test scope and thus will not be passed as transitive dependency to your project. In case you really want to exclude a component from being included in the final war/ear (but available during compilation), see Is there a way to exclude a Maven dependency globally?
Upvotes: 4