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:
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.
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.
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.
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.
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.
I would suggest to use:
mvn -Dmaven.test.failure.ignore=true --fail-at-end clean install
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With