19

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 NoClassDefFoundError on RunListener - which is located in the unit jar. As you can see from the log below - JUnit is included in the classpath.

The error seems to appear completely at random.

Log

Waiting for Jenkins to finish collecting data
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.17:test (default-test) on project taboola-svc: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.17:test failed: A required class was missing while executing org.apache.maven.plugins:maven-surefire-plugin:2.17:test: org/junit/runner/notification/RunListener
[ERROR] -----------------------------------------------------
[ERROR] realm =    plugin>org.apache.maven.plugins:maven-surefire-plugin:2.17
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
[ERROR] urls[0] = file:/home/builder/.m2/repository/org/apache/maven/plugins/maven-surefire-plugin/2.17/maven-surefire-plugin-2.17.jar
[ERROR] urls[1] = file:/home/builder/.m2/repository/org/apache/maven/surefire/surefire-junit47/2.17/surefire-junit47-2.17.jar
[ERROR] urls[2] = file:/home/builder/.m2/repository/org/apache/maven/surefire/common-junit48/2.17/common-junit48-2.17.jar
[ERROR] urls[3] = file:/home/builder/.m2/repository/org/apache/maven/surefire/common-junit4/2.17/common-junit4-2.17.jar
[ERROR] urls[4] = file:/home/builder/.m2/repository/org/apache/maven/surefire/common-junit3/2.17/common-junit3-2.17.jar
[ERROR] urls[5] = file:/home/builder/.m2/repository/org/apache/maven/surefire/surefire-grouper/2.17/surefire-grouper-2.17.jar
[ERROR] urls[6] = file:/home/builder/.m2/repository/org/apache/maven/shared/maven-shared-utils/0.4/maven-shared-utils-0.4.jar
[ERROR] urls[7] = file:/home/builder/.m2/repository/org/apache/maven/surefire/common-java5/2.17/common-java5-2.17.jar
[ERROR] urls[8] = file:/home/builder/.m2/repository/junit/junit/4.11/junit-4.11.jar
[ERROR] urls[9] = file:/home/builder/.m2/repository/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar
[ERROR] urls[10] = file:/home/builder/.m2/repository/org/apache/maven/surefire/maven-surefire-common/2.17/maven-surefire-common-2.17.jar
[ERROR] urls[11] = file:/home/builder/.m2/repository/org/apache/maven/surefire/surefire-booter/2.17/surefire-booter-2.17.jar
[ERROR] urls[12] = file:/home/builder/.m2/repository/org/codehaus/plexus/plexus-utils/1.5.1/plexus-utils-1.5.1.jar
[ERROR] urls[13] = file:/home/builder/.m2/repository/org/apache/maven/reporting/maven-reporting-api/2.0.9/maven-reporting-api-2.0.9.jar
[ERROR] urls[14] = file:/home/builder/.m2/repository/org/apache/commons/commons-lang3/3.1/commons-lang3-3.1.jar
[ERROR] urls[15] = file:/home/builder/.m2/repository/org/apache/maven/surefire/surefire-api/2.17/surefire-api-2.17.jar
[ERROR] urls[16] = file:/home/builder/.m2/repository/org/apache/maven/plugin-tools/maven-plugin-annotations/3.2/maven-plugin-annotations-3.2.jar
[ERROR] Number of foreign imports: 1
[ERROR] import: Entry[import  from realm ClassRealm[maven.api, parent: null]]
[ERROR] 
[ERROR] -----------------------------------------------------: org.junit.runner.notification.RunListener
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.17:test (default-test) on project taboola-svc: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.17:test failed: A required class was missing while executing org.apache.maven.plugins:maven-surefire-plugin:2.17:test: org/junit/runner/notification/RunListener
-----------------------------------------------------
realm =    plugin>org.apache.maven.plugins:maven-surefire-plugin:2.17
strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
urls[0] = file:/home/builder/.m2/repository/org/apache/maven/plugins/maven-surefire-plugin/2.17/maven-surefire-plugin-2.17.jar
urls[1] = file:/home/builder/.m2/repository/org/apache/maven/surefire/surefire-junit47/2.17/surefire-junit47-2.17.jar
urls[2] = file:/home/builder/.m2/repository/org/apache/maven/surefire/common-junit48/2.17/common-junit48-2.17.jar
urls[3] = file:/home/builder/.m2/repository/org/apache/maven/surefire/common-junit4/2.17/common-junit4-2.17.jar
urls[4] = file:/home/builder/.m2/repository/org/apache/maven/surefire/common-junit3/2.17/common-junit3-2.17.jar
urls[5] = file:/home/builder/.m2/repository/org/apache/maven/surefire/surefire-grouper/2.17/surefire-grouper-2.17.jar
urls[6] = file:/home/builder/.m2/repository/org/apache/maven/shared/maven-shared-utils/0.4/maven-shared-utils-0.4.jar
urls[7] = file:/home/builder/.m2/repository/org/apache/maven/surefire/common-java5/2.17/common-java5-2.17.jar
urls[8] = file:/home/builder/.m2/repository/junit/junit/4.11/junit-4.11.jar
urls[9] = file:/home/builder/.m2/repository/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar
urls[10] = file:/home/builder/.m2/repository/org/apache/maven/surefire/maven-surefire-common/2.17/maven-surefire-common-2.17.jar
urls[11] = file:/home/builder/.m2/repository/org/apache/maven/surefire/surefire-booter/2.17/surefire-booter-2.17.jar
urls[12] = file:/home/builder/.m2/repository/org/codehaus/plexus/plexus-utils/1.5.1/plexus-utils-1.5.1.jar
urls[13] = file:/home/builder/.m2/repository/org/apache/maven/reporting/maven-reporting-api/2.0.9/maven-reporting-api-2.0.9.jar
urls[14] = file:/home/builder/.m2/repository/org/apache/commons/commons-lang3/3.1/commons-lang3-3.1.jar
urls[15] = file:/home/builder/.m2/repository/org/apache/maven/surefire/surefire-api/2.17/surefire-api-2.17.jar
urls[16] = file:/home/builder/.m2/repository/org/apache/maven/plugin-tools/maven-plugin-annotations/3.2/maven-plugin-annotations-3.2.jar
Number of foreign imports: 1
import: Entry[import  from realm ClassRealm[maven.api, parent: null]]

-----------------------------------------------------

    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:225)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
    at org.apache.maven.lifecycle.internal.LifecycleThreadedBuilder$1.call(LifecycleThreadedBuilder.java:167)
    at org.apache.maven.lifecycle.internal.LifecycleThreadedBuilder$1.call(LifecycleThreadedBuilder.java:163)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:439)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
    at java.lang.Thread.run(Thread.java:662)
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.17:test failed: A required class was missing while executing org.apache.maven.plugins:maven-surefire-plugin:2.17:test: org/junit/runner/notification/RunListener
-----------------------------------------------------
realm =    plugin>org.apache.maven.plugins:maven-surefire-plugin:2.17
strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
urls[0] = file:/home/builder/.m2/repository/org/apache/maven/plugins/maven-surefire-plugin/2.17/maven-surefire-plugin-2.17.jar
urls[1] = file:/home/builder/.m2/repository/org/apache/maven/surefire/surefire-junit47/2.17/surefire-junit47-2.17.jar
urls[2] = file:/home/builder/.m2/repository/org/apache/maven/surefire/common-junit48/2.17/common-junit48-2.17.jar
urls[3] = file:/home/builder/.m2/repository/org/apache/maven/surefire/common-junit4/2.17/common-junit4-2.17.jar
urls[4] = file:/home/builder/.m2/repository/org/apache/maven/surefire/common-junit3/2.17/common-junit3-2.17.jar
urls[5] = file:/home/builder/.m2/repository/org/apache/maven/surefire/surefire-grouper/2.17/surefire-grouper-2.17.jar
urls[6] = file:/home/builder/.m2/repository/org/apache/maven/shared/maven-shared-utils/0.4/maven-shared-utils-0.4.jar
urls[7] = file:/home/builder/.m2/repository/org/apache/maven/surefire/common-java5/2.17/common-java5-2.17.jar
urls[8] = file:/home/builder/.m2/repository/junit/junit/4.11/junit-4.11.jar
urls[9] = file:/home/builder/.m2/repository/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar
urls[10] = file:/home/builder/.m2/repository/org/apache/maven/surefire/maven-surefire-common/2.17/maven-surefire-common-2.17.jar
urls[11] = file:/home/builder/.m2/repository/org/apache/maven/surefire/surefire-booter/2.17/surefire-booter-2.17.jar
urls[12] = file:/home/builder/.m2/repository/org/codehaus/plexus/plexus-utils/1.5.1/plexus-utils-1.5.1.jar
urls[13] = file:/home/builder/.m2/repository/org/apache/maven/reporting/maven-reporting-api/2.0.9/maven-reporting-api-2.0.9.jar
urls[14] = file:/home/builder/.m2/repository/org/apache/commons/commons-lang3/3.1/commons-lang3-3.1.jar
urls[15] = file:/home/builder/.m2/repository/org/apache/maven/surefire/surefire-api/2.17/surefire-api-2.17.jar
urls[16] = file:/home/builder/.m2/repository/org/apache/maven/plugin-tools/maven-plugin-annotations/3.2/maven-plugin-annotations-3.2.jar
Number of foreign imports: 1
import: Entry[import  from realm ClassRealm[maven.api, parent: null]]

-----------------------------------------------------

    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:127)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
    ... 13 more
Caused by: org.apache.maven.plugin.PluginContainerException: A required class was missing while executing org.apache.maven.plugins:maven-surefire-plugin:2.17:test: org/junit/runner/notification/RunListener
-----------------------------------------------------
realm =    plugin>org.apache.maven.plugins:maven-surefire-plugin:2.17
strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
urls[0] = file:/home/builder/.m2/repository/org/apache/maven/plugins/maven-surefire-plugin/2.17/maven-surefire-plugin-2.17.jar
urls[1] = file:/home/builder/.m2/repository/org/apache/maven/surefire/surefire-junit47/2.17/surefire-junit47-2.17.jar
urls[2] = file:/home/builder/.m2/repository/org/apache/maven/surefire/common-junit48/2.17/common-junit48-2.17.jar
urls[3] = file:/home/builder/.m2/repository/org/apache/maven/surefire/common-junit4/2.17/common-junit4-2.17.jar
urls[4] = file:/home/builder/.m2/repository/org/apache/maven/surefire/common-junit3/2.17/common-junit3-2.17.jar
urls[5] = file:/home/builder/.m2/repository/org/apache/maven/surefire/surefire-grouper/2.17/surefire-grouper-2.17.jar
urls[6] = file:/home/builder/.m2/repository/org/apache/maven/shared/maven-shared-utils/0.4/maven-shared-utils-0.4.jar
urls[7] = file:/home/builder/.m2/repository/org/apache/maven/surefire/common-java5/2.17/common-java5-2.17.jar
urls[8] = file:/home/builder/.m2/repository/junit/junit/4.11/junit-4.11.jar
urls[9] = file:/home/builder/.m2/repository/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar
urls[10] = file:/home/builder/.m2/repository/org/apache/maven/surefire/maven-surefire-common/2.17/maven-surefire-common-2.17.jar
urls[11] = file:/home/builder/.m2/repository/org/apache/maven/surefire/surefire-booter/2.17/surefire-booter-2.17.jar
urls[12] = file:/home/builder/.m2/repository/org/codehaus/plexus/plexus-utils/1.5.1/plexus-utils-1.5.1.jar
urls[13] = file:/home/builder/.m2/repository/org/apache/maven/reporting/maven-reporting-api/2.0.9/maven-reporting-api-2.0.9.jar
urls[14] = file:/home/builder/.m2/repository/org/apache/commons/commons-lang3/3.1/commons-lang3-3.1.jar
urls[15] = file:/home/builder/.m2/repository/org/apache/maven/surefire/surefire-api/2.17/surefire-api-2.17.jar
urls[16] = file:/home/builder/.m2/repository/org/apache/maven/plugin-tools/maven-plugin-annotations/3.2/maven-plugin-annotations-3.2.jar
Number of foreign imports: 1
import: Entry[import  from realm ClassRealm[maven.api, parent: null]]

-----------------------------------------------------

    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:125)
    ... 14 more
Caused by: java.lang.NoClassDefFoundError: org/junit/runner/notification/RunListener
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
    at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    at org.apache.maven.surefire.booter.IsolatedClassLoader.loadClass(IsolatedClassLoader.java:97)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
    at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    at org.apache.maven.surefire.booter.IsolatedClassLoader.loadClass(IsolatedClassLoader.java:97)
    at java.lang.Class.getDeclaredConstructors0(Native Method)
    at java.lang.Class.privateGetDeclaredConstructors(Class.java:2398)
    at java.lang.Class.getConstructor0(Class.java:2708)
    at java.lang.Class.getConstructor(Class.java:1659)
    at org.apache.maven.surefire.util.ReflectionUtils.getConstructor(ReflectionUtils.java:76)
    at org.apache.maven.surefire.util.ReflectionUtils.instantiateOneArg(ReflectionUtils.java:129)
    at org.apache.maven.surefire.booter.SurefireReflector.instantiateProvider(SurefireReflector.java:235)
    at org.apache.maven.surefire.booter.ProviderFactory.createProvider(ProviderFactory.java:113)
    at org.apache.maven.plugin.surefire.booterclient.ForkStarter.getSuitesIterator(ForkStarter.java:512)
    at org.apache.maven.plugin.surefire.booterclient.ForkStarter.runSuitesForkPerTestSet(ForkStarter.java:277)
    at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:169)
    at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeProvider(AbstractSurefireMojo.java:967)
    at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeAfterPreconditionsChecked(AbstractSurefireMojo.java:831)
    at org.apache.maven.plugin.surefire.AbstractSurefireMojo.execute(AbstractSurefireMojo.java:729)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
    ... 14 more
Caused by: java.lang.ClassNotFoundException: org.junit.runner.notification.RunListener
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    at org.apache.maven.surefire.booter.IsolatedClassLoader.loadClass(IsolatedClassLoader.java:97)
    ... 53 more
[ERROR] 
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginContainerException
[ERROR] 
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <goals> -rf :taboola-svc

More Info

  • The build is running on a slave
  • Jenkins ver. 1.565.2
  • Tried with both maven 3.0.4, and 3.1.1
  • Tried with surefire 2.16, 17 & 18
  • Tried with junit 4.10 & 4.11

I have verified the SHA1 of JUnit jar in the Maven repository and made sure the jar file is not corrupted.


Command line

(defined in a jenkins job)

clean install -P FastTests -DIsBuildSystem=1 -T 4 -X -e

Relevant parts from the parent pom.xml

The project itself is a multi module pom project, with the parent pom defining the surefire definitions as attached.

....

        <!-- Generic tests plugin for maven -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>${testing.surefire.version}</version>
            <configuration>

                <systemPropertyVariables>
                    <startPortForDebug>${startPortForDebug}</startPortForDebug>
                    <surefireForkNumber>fork_${surefire.forkNumber}</surefireForkNumber>
                    <geoip.db.dir>${basedir}/../framework/target/</geoip.db.dir>
                    <java.awt.headless>true</java.awt.headless>
                    <redirectTestOutputToFile>true</redirectTestOutputToFile>
                </systemPropertyVariables>



                <!-- Use new JVM for each test -->
                <parallel>classes</parallel>

                <threadCount>1</threadCount>
                <forkCount>${testing.forkCount}</forkCount>
                <reuseForks>${testing.reuseFork}</reuseForks>
                <useSystemClassLoader>${testing.useSystemClassLoader}</useSystemClassLoader>
                <useManifestOnlyJar>${testing.useManifestOnlyJar}</useManifestOnlyJar>

                <!-- Display extra information on exception prints -->
                <useFile>true</useFile>
                <redirectTestOutputToFile>true</redirectTestOutputToFile>
                <runOrder>alphabetical</runOrder>

                <!-- Display extra information on exception prints -->
                <useFile>false</useFile>

                <!-- -->
                <forkedProcessTimeoutInSeconds>300</forkedProcessTimeoutInSeconds>


                <argLine>-XX:PermSize=128m -XX:MaxPermSize=512m -DIsBuildSystem=${is.build.system}</argLine>

            </configuration>
            <dependencies>
                <dependency>
                    <groupId>org.apache.maven.surefire</groupId>
                    <artifactId>surefire-junit47</artifactId>
                    <version>${testing.surefire.version}</version>
                </dependency>
                <dependency>
                    <groupId>junit</groupId>
                    <artifactId>junit</artifactId>
                    <version>${junit.version}</version>
                </dependency>
            </dependencies>

        </plugin>

....
        <profile>
            <id>FastTests</id>
            <properties>
                <testing.forkCount>0.5C</testing.forkCount>
                <testing.reuseFork>false</testing.reuseFork>
                <testing.useSystemClassLoader>true</testing.useSystemClassLoader>
                <testing.useManifestOnlyJar>false</testing.useManifestOnlyJar>
            </properties>
        </profile>
Ferrybig
  • 18,194
  • 6
  • 57
  • 79
Nitzan Volman
  • 1,809
  • 3
  • 17
  • 31
  • it would be awesome if you could include your pom.xml and the command line you're having jenkins run ;) – Vogel612 Dec 01 '14 at 09:28
  • @Vogel612 thanks, added the command line for maven, and pasted the relevant code from the pom.xml. – Nitzan Volman Dec 01 '14 at 09:47
  • Have you tried the latest Maven? I think it's up to 3.2.3 now. Also - what happens if you run Maven alone, without Jenkins? Is the Jenkins project a Freestyle project or Maven? – user944849 Dec 01 '14 at 14:40
  • Disclaimer before this reaches meta on sockpuppetry accusations: Nitzan is my colleague. – Madara's Ghost Dec 03 '14 at 11:45

5 Answers5

12

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.

Foxsly
  • 1,028
  • 6
  • 14
  • the -T option is pretty important (and saves about 50% of the build time), I am looking for either a way to run this with the parallel option enabled, or proof that this is not possible. – Nitzan Volman Dec 02 '14 at 12:47
  • Have you tried running it without the parallel option? Figure out how often it was failing before (every 5 runs? every 10?), and then try running it multiple times without the parallel option. It might take some time, but if you don't experience the issue after running it without the issue, I'd be fairly comfortable calling that the cause. Also, you may have better results if you lower `4` to `3` or `2` - less threads running at the same time would result in less chances of a thread concurrency issue. – Foxsly Dec 02 '14 at 13:15
  • i tried it without the parallel option and it did not fail - the issue is probably related to the -T option; that doesn’t mean there is no way overcome while still using the *much* faster parallel option. As i mentioned I would like a way to achieve WITH parallel, or proof that this is not possible. – Nitzan Volman Dec 03 '14 at 11:47
  • Try upgrading to maven surefire 2.6 - the link in my answer indicates that that's a threadsafe version of surefire. – Foxsly Dec 03 '14 at 15:42
  • tried running this with surefire 2.16,17 & 18. All should contain the thread safe fixes in 2.6. – Nitzan Volman Dec 03 '14 at 16:04
  • @NitzanVolman I believe there is a dependency that is using plexus-utils-1.5.1 that needs to be upgraded. I've updated my answer - take a look and see if that solves your problem. – Foxsly Dec 03 '14 at 23:53
  • Actually according to the [Surefire documentation](http://maven.apache.org/surefire/maven-surefire-plugin/examples/junit.html#Provider_Selection), manual provider selection should not be necessary at all if JUnit is defined as a dependency in the POM. Can you try to get rid of the provider selection altogether and see what happens? – kriegaex Dec 07 '14 at 11:08
  • Did not mark this answer as correct since strictly speaking it is not, but it provides the most helpful information about the problem. It is caused by an older unsafe version of plexus, but surefire is not the only plugin that may contain this. in our case it was surefire, and a few other plugins (some of them were home grown mojo's). once we completely removed all the dependencies on the old plexus, that fixed the issue. – Nitzan Volman Aug 31 '15 at 10:28
2

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 :

enter image description here

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 ?

Donatello
  • 3,486
  • 3
  • 32
  • 38
1

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 :

  • execute : mvn -X clean test
  • open file : target\surefire\surefire5942929663635698632tmp

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 :

surfire-junit47 dependencies

                <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>
Donatello
  • 3,486
  • 3
  • 32
  • 38
1
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.0.0-M5</version>                 
                <dependencies>
                  <dependency>
                    <groupId>org.apache.maven.surefire</groupId>
                    <artifactId>surefire-junit47</artifactId>
                    <version>3.0.0-M5</version>
                  </dependency>
                </dependencies>
                <configuration>
                    <parallel>suites</parallel>                     
                    <threadCount>10</threadCount>
                    <redirectTestOutputToFile>true</redirectTestOutputToFile>
                    <forkCount>3</forkCount>
                    <reuseForks>true</reuseForks>                       
                    <argLine>-Xms1536m -Xmx1536m</argLine>
                    <workingDirectory>${project.build.directory}/${surefire.forkNumber}</workingDirectory>
                    <useSystemClassLoader>true</useSystemClassLoader>
                    <useManifestOnlyJar>false</useManifestOnlyJar>
                    <rerunFailingTestsCount>2</rerunFailingTestsCount>
                    <shutdown>exit</shutdown>
                </configuration>                    
            </plugin>
Rajkiran
  • 61
  • 2
  • 8
  • This configuration helped us to achive 33% reduction in integration test execution time. The no of threads 10 in the config gets multiplied by no. of cores of the CPU, we tested it with 2 core CPU & 12 gb RAM, more the no. of cores of CPU and a decent RAM supporting it the greater will be a reduction in the test execution time. – Rajkiran Nov 23 '21 at 04:21
0

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.

RichW
  • 2,004
  • 2
  • 15
  • 24