Maven - Configuring Run Job Execution Always

In my project POM file, I need to set up a post run step . those. after running the unit tests, post exec. the task will parse the testng-xml-report and generate a statistics page. The report will be generated by a separate bank. This Jar will be called in the verify

POM phase .

But the current problem is that for a test success scenario in a phase, test

it will call Jar and work correctly. For failure case, an xml report will be generated, but since the phase is test

not running, it will not continue the phase verify


So that I can point out that should run the event the maven-the exec-plugin the exec to invoke Jar, regardless of whether the phase test

is a success or not.


source to share

2 answers

The correct solution for this scenario is not to skip tests. The tests should record a failure (eg in an XML report), but the runner should return "success" to Maven.

For Surefire, you can achieve this with-DtestFailureIgnore=true

EDIT You can put this in your POM to activate it permanently.

But if you call maven for different purposes, the results may be unwanted. For example, for mvn deploy

, you probably want the process to stop when there are testing errors.

To fix this, you have two options:

  • Write a script that calls Maven with the required parameters to generate a test report
  • Move the parameter to profile

[EDIT] Details about option # 1: You can write a shell script that starts Maven with -DtestFailureIgnore=true

to generate reports.

Then you need a utility that can find XML reports and check if there are any errors in it. If you are using Java to do this, call System.exit(1)

if you find errors. If you prefer the command line, use XMLStarlet to run an XML query and a tool such as find(1)

to find XML files. If you need help, please post new questions.

Call this utility after Maven in your shell script with util || exit 1

- this will stop the shell script with an error code 1

if the utility encounters an error.

Use this script to build instead of the embedded Maven runner.



you can use mvn -fn clean install


means "fail-never" and it will continue even if the segment fails.

For more details see mvn -help



All Articles