Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compile all maven modules even if tests fail, but fail overall build if any tests fail

Tags:

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

Running:

mvn clean install

stops at the first failing module.

If you add:

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 //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. compile all modules
  2. run tests on all modules
  3. If a module's tests fail but the code compiles dependent modules still get compiled and tested

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.

like image 346
Alex Avatar asked May 23 '14 15:05

Alex


People also ask

How do I skip failed test cases in Maven?

To skip running the tests for a particular project, set the skipTests property to true. You can also skip the tests via the command line by executing the following command: mvn install -DskipTests.

Can two Maven modules depend on each other?

Because modules within a multi-module build can depend on each other, it is important that the reactor sorts all the projects in a way that guarantees any project is built before it is required. The following relationships are honoured when sorting projects: a project dependency on another module in the build.

What is the Maven command to compile all files including the test files?

mvn compile: Compiles source code of the project. mvn test-compile: Compiles the test source code. mvn test: Runs tests for the project. mvn package: Creates JAR or WAR file for the project to convert it into a distributable format.

How do you write a resume in Maven after failing?

With Maven 4, you can make your life even easier and use --resume , or -r for short. It will automatically resume the build from the module that last failed.


2 Answers

I would suggest to use:

mvn -Dmaven.test.failure.ignore=true --fail-at-end clean install
like image 133
khmarbaise Avatar answered Nov 14 '22 07:11

khmarbaise


I would suggest to split it into two mvn calls:

mvn clean compile
mvn -fae install

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.

like image 41
sradi Avatar answered Nov 14 '22 07:11

sradi