We are building a large multi module Maven project on Jenkins, including running a large number of unit test.
Once every few builds the build fails on NoClassDefF
If all your builds use the same workspace, and if its possible for several builds to run concurrently or overlap in any way, it's possible that the "clean" action is wiping out required build artifacts while another build is trying to use them.
If that's what's happening, the fix would be to have each build run use its own workspace.
Just try to use the surfire-junit4
in place of surfire-junit47
:
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit4</artifactId>
<version>${testing.surefire.version}</version>
</dependency>
It will change classpath/runtime behavior, as it comes with less dependencies :
You may also try to completely remove this dependency as it's not required for parallel support :
http://maven.apache.org/surefire/maven-surefire-plugin/examples/junit.html
As of Surefire 2.7, no additional dependencies are needed to use the full set of options with parallel. As of Surefire 2.16, new thread-count attributes are introduced, namely threadCountSuites, threadCountClasses and threadCountMethods. Additionally, the new attributes parallelTestsTimeoutInSeconds and parallelTestsTimeoutForcedInSeconds are used to shut down the parallel execution after an elapsed timeout, and the attribute parallel specifies new values.
Does this solve the problem ?
Try running the maven build without the -T 4
.
The parallel builds feature in Maven 3 is still in the experimental stages, and it appears that there are known issues with thread safety in the plexus-utils
library prior to version 2.0.5 - you're using version 1.5.1.
Edit:
Your problem is this dependency:
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>${testing.surefire.version}</version>
</dependency>
surefire-junit47 depends on maven-surefire-common, which in turn depends on maven-artifact, which depends on plexus-utils-1.5.1
. As stated above, this has known thread safety issues, which is likely what is causing your problems. I'm not sure what parts of the surefire-junit47
library you're using, but if switching to surefire-junit4
is an option, then that should solve your problem.
After looking at the docs for the surefire plugin a little more, it looks like you need the surefire-junit47
provider to run parallel tests. I'd try overriding plexus-utils
to be version 2.0.5 and see if that works; otherwise, you can override the maven-artifact
version to 3.0.3 or higher and see if that works.
It seems you have a random classloading issue.
The missing class appears since JUnit 4 : http://findjar.com/class/org/junit/runner/notification/RunListener.html
You should try to analyse surfire classpath by :
You will see something like :
surefireClassPathUrl.0=D\:\\maven2\\repository\\org\\apache\\maven\\surefire\\surefire-junit47\\2.17\\surefire-junit47-2.17.jar
surefireClassPathUrl.1=D\:\\maven2\\repository\\org\\apache\\maven\\surefire\\common-junit48\\2.17\\common-junit48-2.17.jar
surefireClassPathUrl.2=D\:\\maven2\\repository\\org\\apache\\maven\\surefire\\common-junit4\\2.17\\common-junit4-2.17.jar
surefireClassPathUrl.3=D\:\\maven2\\repository\\org\\apache\\maven\\surefire\\common-junit3\\2.17\\common-junit3-2.17.jar
surefireClassPathUrl.4=D\:\\maven2\\repository\\org\\apache\\maven\\surefire\\surefire-api\\2.17\\surefire-api-2.17.jar
surefireClassPathUrl.5=D\:\\maven2\\repository\\org\\apache\\maven\\surefire\\common-java5\\2.17\\common-java5-2.17.jar
surefireClassPathUrl.6=D\:\\maven2\\repository\\org\\apache\\maven\\shared\\maven-shared-utils\\0.4\\maven-shared-utils-0.4.jar
surefireClassPathUrl.7=D\:\\maven2\\repository\\com\\google\\code\\findbugs\\jsr305\\2.0.1\\jsr305-2.0.1.jar
surefireClassPathUrl.8=D\:\\maven2\\repository\\org\\apache\\maven\\surefire\\surefire-grouper\\2.17\\surefire-grouper-2.17.jar
Try to ensure JUnit 3.x -and related jars- are not loaded.
For example, you may try to exclude common-junit3 from surfire-junit47 :
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>2.17</version>
<exclusions>
<exclusion>
<groupId>org.apache.maven.surfire</groupId>
<artifactId>common-junit3</artifactId>
</exclusion>
</exclusions>
</dependency>