是否可以在多模块 Maven 项目中运行 Maven 测试构建(mvn clean test
)并跳过/忽略特定模块的测试?喜欢-Dmaven.test.skip=true
但对于特定模块而不是所有模块?我不想改变 surefire <configuration>
包括 <skipTests>true</skipTests>
对于我想跳过测试的模块。我想知道这是否可以从命令行完成。我需要这个,因为在我的项目中,我有很多模块,特别是一两个模块需要很长时间才能执行测试,所以当我只想测试几个模块时,我想跳过这些时间,使用我没有测试过的模块进行了任何更改。
更改 surefire 插件的配置真的是个问题吗?因为你只能在你的模块中改变它一次......
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
<configuration>
<skipTests>${skip.foo.module.tests}</skipTests>
</configuration>
</plugin>
</plugins>
</build>
... 并将 skipTests 标记的真/假值委托(delegate)给 maven 属性,由专用配置文件激活:
<properties>
<skip.foo.module.tests>false</skip.foo.module.tests>
</properties>
<profiles>
<profile>
<id>SKIP_FOO_MODULE_TESTS</id>
<properties>
<skip.foo.module.tests>true</skip.foo.module.tests>
</properties>
</profile>
</profiles>
这样您就可以使用命令行停用 Foo 模块中的测试:
mvn clean test -P SKIP_FOO_MODULE_TESTS