How to build a jar using maven, ignoring test results?

user398920 picture user398920 · Jul 29, 2010 · Viewed 92k times · Source

Actuality when i run tests they fails but i need to run them to get some .class files which are very important for my jar.

By default when test results fails , the jar is not build , could i add a setting in pom.xml which ignore that, so I can build the jar ignoring results from tests ?

I read something about "Maven Surefire Plugin" but I don't know how to use it...

Answer

Zilvinas picture Zilvinas · May 22, 2013

Please refer to surefire:test for details, but the most useful properties are:

-Dmaven.test.failure.ignore=true (or -DtestFailureIgnore=true) - will ignore any failures occurred during test execution

-Dmaven.test.error.ignore=true ( deprecated ) - will ignore any errors occurred during test execution

-DskipTests - would compile the test classes but skip test execution entirely

-Dmaven.test.skip=true - would not even compile the tests

I believe that in your case where you want to compile test classes but not fail the build due to any tests errors and still create the jar.

You should use the first option to ignore any test failures which you can still review once the build has finished.