Java 如何使用 maven 构建 jar,忽略测试结果?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3365553/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to build a jar using maven, ignoring test results?
提问by user398920
Actuality when i run tests they fails but i need to run them to get some .class files which are very important for my jar.
实际上,当我运行测试时,它们失败了,但我需要运行它们来获取一些对我的 jar 非常重要的 .class 文件。
By default when test results fails , the jar is not build , could i add a setting in pom.xml which ignore that, so I can build the jar ignoring results from tests ?
默认情况下,当测试结果失败时,jar 不会构建,我可以在 pom.xml 中添加一个忽略它的设置,这样我就可以构建忽略测试结果的 jar 吗?
I read something about "Maven Surefire Plugin" but I don't know how to use it...
我读了一些关于“Maven Surefire Plugin”的东西,但我不知道如何使用它......
回答by I82Much
<properties>
<maven.test.skip>true</maven.test.skip>
<maven.test.failure.ignore>true</maven.test.failure.ignore>
</properties>
http://jira.codehaus.org/browse/SUREFIRE-319
http://jira.codehaus.org/browse/SUREFIRE-319
Or from command line
或者从命令行
http://maven.apache.org/maven-1.x/plugins/test/properties.html
http://maven.apache.org/maven-1.x/plugins/test/properties.html
maven.test.error.ignore Yes Set this to true to ignore errors during testing. Its use is NOT RECOMMENDED, but quite convenient on occasion
maven.test.error.ignore 是 将此设置为 true 以忽略测试期间的错误。不推荐使用,但有时很方便
回答by fasseg
mvn -Dmaven.test.skip=true package
skips the surefire test mojo.
mvn -Dmaven.test.skip=true package
跳过万无一失的测试魔咒。
to ignore test failures and keep maven from stopping you can add this to the section of the pom.xml:
要忽略测试失败并防止 maven 停止,您可以将其添加到 pom.xml 的部分:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
回答by Jordan Allan
Use the maven option -Dmaven.test.skip=true
使用 maven 选项 -Dmaven.test.skip=true
E.g. mvn package -Dmaven.test.skip=true
例如 mvn package -Dmaven.test.skip=true
回答by Sean Patrick Floyd
The solution is:
解决办法是:
mvn -fn clean install
execute mvn --help
for advanced options
执行mvn --help
高级选项
Here's the excerpt for -fn
这是 -fn 的摘录
-fn,--fail-never NEVER fail the build, regardless
of project result
回答by Julien Carsique
Use -DskipTests=true instead of -Dmaven.test.skip=true in order to skip tests but compile them.
使用 -DskipTests=true 而不是 -Dmaven.test.skip=true 以跳过测试但编译它们。
Using -Dmaven.test.failure.ignore=true will also work but is not very nice.
使用 -Dmaven.test.failure.ignore=true 也可以工作,但不是很好。
回答by Zilvinas
Please refer to surefire:testfor details, but the most useful properties are:
有关详细信息,请参阅surefire:test,但最有用的属性是:
-Dmaven.test.failure.ignore=true(or -DtestFailureIgnore=true) - will ignore any failures occurred during test execution
-Dmaven.test.failure.ignore=true(或-DtestFailureIgnore=true) - 将忽略测试执行期间发生的任何失败
-Dmaven.test.error.ignore=true( deprecated ) - will ignore any errors occurred during test execution
-Dmaven.test.error.ignore=true( deprecated ) - 将忽略测试执行期间发生的任何错误
-DskipTests- would compile the test classes but skip test execution entirely
-DskipTests- 将编译测试类但完全跳过测试执行
-Dmaven.test.skip=true- would not even compile the tests
-Dmaven.test.skip=true- 甚至不会编译测试
I believe that in your case where you want to compile test classesbut not fail the build due to any tests errors and still create the jar.
我相信在您想要编译测试类但不会由于任何测试错误而导致构建失败并仍然创建 jar 的情况下。
You should use the first option to ignore any test failures which you can still review once the build has finished.
您应该使用第一个选项来忽略任何测试失败,一旦构建完成,您仍然可以查看这些失败。