如何使用maven构建jar,忽略测试结果?

use*_*920 104 java testing maven-2 jar

当我运行测试他们失败但是我需要运行它们以获得一些对我的jar非常重要的.class文件的现状.

默认情况下,当测试结果失败时,jar不是构建的,我可以在pom.xml中添加一个忽略它的设置,所以我可以构建jar忽略测试结果吗?

我读了一些关于"Maven Surefire插件"的内容,但我不知道如何使用它...

Zil*_*nas 167

有关详细信息,请参阅surefire:test,但最有用的属性是:

-Dmaven.test.failure.ignore = true(或-DtestFailureIgnore = true) - 将忽略测试执行期间发生的任何故障

-Dmaven.test.error.ignore = true(不建议使用) - 将忽略测试执行期间发生的任何错误

-DskipTests - 将编译测试类,但完全跳过测试执行

-Dmaven.test.skip = true - 甚至不编译测试

我相信在你想要编译测试类的情况下,但由于任何测试错误而导致构建失败,并且仍然会创建jar.

您应该使用第一个选项来忽略在构建完成后仍可以查看的任何测试失败.


fas*_*seg 41

mvn -Dmaven.test.skip=true package 跳过surefire测试mojo.

要忽略测试失败并让maven停止,你可以将它添加到pom.xml的部分:

 <plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-surefire-plugin</artifactId>
   <configuration>
     <testFailureIgnore>true</testFailureIgnore>
   </configuration>
 </plugin>
Run Code Online (Sandbox Code Playgroud)

  • 这不是挑剔,这是正确的.所有这些建议跳过测试的答案都是不正确的,他们忽略了这一点:问题不是跳过测试,而是忽略测试失败. (5认同)
  • `mvn -Dmaven.test.skip = true包跳过测试阶段`.**不,不!**.您不能使用系统属性跳过阶段.它做的是设置一个跳过surefire执行的标志:test mojo和编译器:test-compile mojo(可能还有其他):http://maven.apache.org/plugins/maven-surefire-plugin/test-mojo .html #skip http://maven.apache.org/plugins/maven-compiler-plugin/testCompile-mojo.html#skip (4认同)

Sea*_*oyd 25

解决方案是:

mvn -fn clean install
Run Code Online (Sandbox Code Playgroud)

执行mvn --help高级选项

这是-fn的摘录

 -fn,--fail-never         NEVER fail the build, regardless
                          of project result
Run Code Online (Sandbox Code Playgroud)


I82*_*uch 18

<properties>
<maven.test.skip>true</maven.test.skip>
<maven.test.failure.ignore>true</maven.test.failure.ignore>
</properties>
Run Code Online (Sandbox Code Playgroud)

http://jira.codehaus.org/browse/SUREFIRE-319

或者从命令行

http://maven.apache.org/maven-1.x/plugins/test/properties.html

maven.test.error.ignore是将此设置为true以忽略测试期间的错误.它的使用不推荐,但偶尔也很方便


Jul*_*que 5

使用-DskipTests=true而不是-Dmaven.test.skip=true为了跳过测试但编译它们。

使用-Dmaven.test.failure.ignore=true也可以,但不是很好。

  • 如果从测试类生成的“test-jar”类型用作其他模块中的依赖项,则如果我们使用“-Dmaven.test.skip=true”,整个​​编译将失败。虽然 -DskipTests=true 编译并生成 jar 但不运行测试。:) (2认同)