如何仅在java中排除测试范围的依赖

Gal*_*let 4 java pom.xml maven-dependency

我只想排除测试范围的依赖项。

例子:-

我的项目中有两个不同的地方使用了 commons-lang3 依赖项。我只想排除测试范围的这种依赖性。

<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-lang3</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)

我怎么能这样做?

nai*_*fei 5

您可以配置classpathat surefire 插件。像下面这样:

<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>
Run Code Online (Sandbox Code Playgroud)

有关更多信息,请删除依赖类路径元素