Maven:在生命周期中跳过测试编译?
我有一个项目,我设置使用此设置使用 test-jar
和普通 jar 进行构建:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
问题是每当我在 pom 中升级项目版本时,我需要使用以下命令进行构建测试,否则 Maven 将无法在 test-compile
阶段找到正确版本的 test-jar。很多时候我只想跳过测试,但由于缺少 test-jar,test-compile
短语将会失败。
我尝试使用 -Dmaven.test.skip=true ,但这似乎并没有跳过测试编译阶段。有办法跳过这个吗?
I have project that I set to build with the test-jar
and normal jar by using this setting:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
The problem with this is whenever I upgrade the project version in the pom, I need to do a build with the tests, otherwise maven won't be able to find the test-jar with the correct version during the test-compile
phrase. A lot of time I would just want to skip the tests, but due to the test-jar missing, the test-compile
phrase will fail.
I tried to use -Dmaven.test.skip=true
, but that doesn't seem to skip the test-compile
phase. Is there a way to skip this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果你想跳过测试源的编译,可以尝试配置 maven 编译器插件 适当。但不建议这样做。
If you want to skip the compilation of test sources, you can try configuring the maven compiler plugin suitably. This is not recommended though.
有点晚了,但是简单而准确地总结一下 -
添加 @Sridhar 和 @FWDekker 说,
mvn clean install -DskipTests=true
将跳过测试执行mvn clean install -Dmaven .test.skip
将跳过测试的编译和执行。Little Late, But to summarise in short and be precise -
Adding to what @Sridhar and @FWDekker said,
mvn clean install -DskipTests=true
will just skip the Tests Executionmvn clean install -Dmaven.test.skip
will skip both compilation and execution of Tests.只需添加 -Dmaven.test.skip 。它甚至不会编译测试
Just Add -Dmaven.test.skip . It will Not even compile test
这是我的工作命令 https://maven.apache.org/plugins-archives/maven-surefire-plugin-2.12.4/examples/skipping-test.html
您可以使用以下命令跳过运行测试以下命令
mvn clean install -DskipTests
如果绝对必要,您还可以使用maven.test.skip属性来跳过编译测试。 maven.test.skip 受到 Surefire、Failsafe 和编译器插件的认可。
mvn clean install -Dmaven.test.skip=true -DskipTests
Here is my working command from https://maven.apache.org/plugins-archives/maven-surefire-plugin-2.12.4/examples/skipping-test.html
You can skip running tests with the following command
mvn clean install -DskipTests
If you absolutely must, you can also use the maven.test.skip property to skip compiling the tests. maven.test.skip is honored by Surefire, Failsafe and the Compiler Plugin.
mvn clean install -Dmaven.test.skip=true -DskipTests