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

JavaTestingMaven 2Jar

Java Problem Overview


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...

Java Solutions


Solution 1 - Java

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.

Solution 2 - Java

mvn -Dmaven.test.skip=true package skips the surefire test mojo.

to ignore test failures and keep maven from stopping you can add this to the section of the pom.xml:

 <plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-surefire-plugin</artifactId>
   <configuration>
     <testFailureIgnore>true</testFailureIgnore>
   </configuration>
 </plugin>

Solution 3 - Java

The solution is:

mvn -fn clean install

execute mvn --help for advanced options

Here's the excerpt for -fn

 -fn,--fail-never         NEVER fail the build, regardless
                          of project result

Solution 4 - Java

<properties>
<maven.test.skip>true</maven.test.skip>
<maven.test.failure.ignore>true</maven.test.failure.ignore>
</properties>

http://jira.codehaus.org/browse/SUREFIRE-319

Or from command line

http://maven.apache.org/maven-1.x/plugins/test/properties.html

> maven.test.error.ignore Yes Set > this to true to ignore errors during > testing. Its use is NOT RECOMMENDED, > but quite convenient on occasion

Solution 5 - Java

Use -DskipTests=true instead of -Dmaven.test.skip=true in order to skip tests but compile them.

Using -Dmaven.test.failure.ignore=true will also work but is not very nice.

Solution 6 - Java

Use the maven option -Dmaven.test.skip=true

E.g. mvn package -Dmaven.test.skip=true

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser398920View Question on Stackoverflow
Solution 1 - JavaZilvinasView Answer on Stackoverflow
Solution 2 - JavafassegView Answer on Stackoverflow
Solution 3 - JavaSean Patrick FloydView Answer on Stackoverflow
Solution 4 - JavaI82MuchView Answer on Stackoverflow
Solution 5 - JavaJulien CarsiqueView Answer on Stackoverflow
Solution 6 - JavaJordan AllanView Answer on Stackoverflow