即使测试失败,如何编译所有maven模块,但如果任何测试失败,则整体构建失败

时间:2014-05-23 15:51:17

标签: maven testing

上下文:我想在多模块项目中编译和测试所有模块如果有任何失败要么编译还是测试我希望整个构建到失败

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

运行:

  

mvn clean install

在第一个失败的模块停止。

如果你添加:

  

mvn clean install -fae //最后失败

然后运行所有模块,但如果测试失败,那么任何相关模块都会被删除:



    [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] -----------------------------------------

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

  

mvn clean install -fn // never never

但这会导致测试失败时构建传递



    [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

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

  1. 编译所有模块
  2. 在所有模块上运行测试
  3. 如果模块的测试失败但代码编译依赖模块仍然可以编译和测试
  4. 非常感谢回复 - 否则我们必须在构建服务器上重复运行测试,如果有多个问题 - 烧掉很多时间。

3 个答案:

答案 0 :(得分:4)

我建议使用:

mvn -Dmaven.test.failure.ignore=true --fail-at-end clean install

答案 1 :(得分:4)

我建议把它分成两个mvn调用:

mvn clean compile
mvn -fae install

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

答案 2 :(得分:2)

这是一种不同的方法:解析maven输出。所以你要么