Sometimes you may find that your tests are run twice, once to make
the report for the site (thus not breaking the build if they fail) and
second time to create a jar, war or any other artifact, and probably in
this step you want the build to break if tests don’t succeed. This is
very common in a continuous integration scenario where the machine with
CruiseControl or any other CI tool deploys the site and generated
artifacts.
My suggestion is to create a goal in your maven.xml like this
<goal name="continuousintegration"> <attainGoal name="clean"/> <attainGoal name="site:deploy"/> <!-- avoid running tests again --> <j:if test="${maven.test.failure}"> <fail message="There were test failures."/> </j:if> <j:set var="maven.test.skip" value="true"/> <attainGoal name="jar:deploy"/> <j:set var="maven.test.skip" value="false"/> </goal>
The trick is checking the maven.test.failure property after creating
the site, if it’s true the build has to fail and if it’s false you can
skip tests in next steps.