How to exclude a dependecy only for test scope in java

3.9k views Asked by At

I want to exclude a dependency only for test scope.

Example:-

commons-lang3 dependency is used in two different places in my project. I want to exclude this dependency for test scope only.

<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-lang3</artifactId>
</dependency>

How can I do so ?

1

There are 1 answers

2
nail fei On

you can configure the classpath at surefire plugin. like below:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>xxx</version>
    <configuration>
      <classpathDependencyExcludes>
        <classpathDependencyExclude>org.apache.commons:commons-lang3</classpathDependencyExclude>
      </classpathDependencyExcludes>
    </configuration>
</plugin>

for more information Removing Dependency Classpath Elements