java Maven Surefire:在指定的依赖项中运行测试
我有一个项目,其中包含多个其他jar工件作为依赖项。我使用surefire插件的dependenciesToScan
属性在上述工件中运行测试,如下所示:
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<dependenciesToScan>
<dependency>com.example.tests:project-a</dependency>
<dependency>com.example.tests:project-b</dependency>
</dependenciesToScan>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.example.tests</groupId>
<artifactId>project-a</artifactId>
</dependency>
<dependency>
<groupId>com.example.tests</groupId>
<artifactId>project-b</artifactId>
</dependency>
</dependencies>
理想情况下,我希望能够做到以下几点:
mvn test
将像正常情况一样在每个依赖项中运行测试- 另一个参数将仅对指定的工件运行测试,而对未包含的依赖项跳过测试
这到底是可能的还是有其他的方法来实现这一点
# 1 楼答案
可以使用profiles生成两个不同的版本
使用
mvn clean test -P project-a
或mvn clean test -P project-b
您还可以在每个配置文件中设置不同的属性,并拥有集中的surefire配置或者你可以使用一个属性:
使用
mvn clean test -DsomeProperty=project-a