即使测试失败,如何编译所有Maven模块,但如果任何测试失败,则如何使整体构建失败 [英] How to compile all maven modules even if tests fail, but fail overall build if any tests fail

查看:81
本文介绍了即使测试失败,如何编译所有Maven模块,但如果任何测试失败,则如何使整体构建失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

上下文:我想在多模块项目中编译和测试所有模块,但是如果有任何失败,无论是编译还是测试,我都希望整体构建为失败.

Context: I want to compile and test all modules in a multi-module project but if any fail either compilation or tests I want the overall build to fail.

默认配置要么在第一次失败时停止,要么在测试失败后跳过模块

Default configurations either stop on the first failure or skip modules after a test failure

运行:

mvn全新安装

mvn clean install

在第一个失败的模块处停止.

stops at the first failing module.

如果添加:

mvn clean install -fae//最后失败

mvn clean install -fae //fail at end

然后所有模块都运行,但是如果测试失败,则跳过所有相关模块:

then all modules are run, but if tests fail then any dependent modules are skpped:



    [INFO] ------------------------------------------------------------------------
    [INFO] Reactor Summary:
    [INFO] ------------------------------------------------------------------------
    [INFO] Module A ............................................. SUCCESS [15.210s]
    [INFO] Module B ............................................. SUCCESS [10.923s]
    [INFO] Module C ............................................. FAILED [1.731s]
    [INFO] Module D ............................................. SUCCESS [3.791s]
    [INFO] Module E ............................................. SUCCESS [1.488s]
    [INFO] Module F ............................................. SKIPPED (dependency build failed or was skipped)
    [INFO] Module G ............................................. SKIPPED (dependency build failed or was skipped)
    [INFO] Module H ............................................. SKIPPED (dependency build failed or was skipped)
    [INFO] Module I ............................................. SUCCESS [1.690s]
    [INFO] -----------------------------------------

另一个强制所有模块编译的选项是:

Another option to force all modules to compile is:

mvn clean install -fn//永不失败

mvn clean install -fn //fail never

但这会导致测试失败时通过构建

but this results in the build passing when tests fail



    [INFO] ------------------------------------------------------------------------
    [INFO] Reactor Summary:
    [INFO] ------------------------------------------------------------------------
    [INFO] Module A ............................................. SUCCESS [15.210s]
    [INFO] Module B ............................................. SUCCESS [10.923s]
    [INFO] Module C ............................................. FAILED [1.731s]
    [INFO] Module D ............................................. SUCCESS [3.791s]
    [INFO] Module E ............................................. SUCCESS [1.488s]
    [INFO] Module F ............................................. SUCCESS [9.062s]
    [INFO] Module G ............................................. SUCCESS [16.324s]
    [INFO] Module H ............................................. SUCCESS [4.032s]
    [INFO] Module I ............................................. SUCCESS [1.690s]
    [INFO] ------------------------------------------------------------------------
    [INFO] Error for project: Module C (during install)
    [INFO] ------------------------------------------------------------------------
    [INFO] There are test failures.

    Please refer to C:\MavenBuildDir\ModuleC\surefire-reports for the
    individual test results.
    [INFO] ------------------------------------------------------------------------
    [INFO] For more information, run Maven with the -e switch
    [INFO] ------------------------------------------------------------------------
    [INFO]  + Ignoring failures
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESSFUL
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 30 minutes 38 seconds
    [INFO] Finished at: Fri May 23 16:42:08 BST 2014
    [INFO] Final Memory: 39M/185M

任何人都可以建议一套实现以下目标的选项:

Can anyone advise a set of options to achieve the following:

  1. 编译所有模块
  2. 在所有模块上运行测试
  3. 如果模块的测试失败,但是依赖于代码编译的模块仍会进行编译和测试

非常感谢您的答复-否则,如果存在多个问题,我们必须在构建服务器上重复运行测试-花费大量时间.

Responses much appreciated - otherwise we have to run the tests repeatedly on the build server if there are multiple issues - burning a lot of time.

推荐答案

我建议将其分为两个mvn调用:

I would suggest to split it into two mvn calls:

mvn clean compile
mvn -fae install

如果存在编译错误,则第一次调用将失败.第二个调用将重用已编译的.class文件,因为省略了"clean".如果存在测试失败,它将最终失败.但是所有模块的编译已经完成.

The first call will fail, if there are compile errors. The second call will reuse the compiled .class-files, since "clean" is omitted. It will fail at the end, if there are test failures. But compilation has already been finished for ALL modules.

这篇关于即使测试失败,如何编译所有Maven模块,但如果任何测试失败,则如何使整体构建失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆