A required class was missing while executing org.apache.maven.plugins:maven-surefire-plugin:2.14.1:test: org/junit/runner/notification/RunListener

13,255

Solution 1

The issue was a combination of two factors:

First, there was a transitive dependency problem (namely that of hamcrest-core 1.1 -> jmock 1.1.0 -> JUnit 3.8.1) where (in Maven's dependency-tree) the older JUnit was 'closer' to the systemTest module (which was inheriting the version dependency), and revision 3.8.1 of JUnit doesn't have contain org.junit.runner.notification.RunListener.

Second, there was confusion over the interpretation of the <version> tag by maven-- having <version>4.10</version> indicates a soft requirement for junit, rather than a hard requirement (which might be indicated with <version>[4.10]</version> (see also Maven Dependency Mediation))

The latter led maven to accept the 'closest' satisfactory JUnit dependency (which in this case was 3.8) rather than the expected value, thereby giving rise to the error. Altering the pom to the [N.mm] 'hard' syntax resolves this problem.

Solution 2

I have been having a similar issue today while rebuilding dev environment. A handful of jars were downloaded incorrectly. I was able to continue by spot-deleting the problem folders from my maven repository. This forced maven to download them again, and then they worked without problem.

In this case I removed:

{local_repo}\org\apache\maven\plugins\maven-surefire-plugin

Share:
13,255
pgreen2
Author by

pgreen2

I am a software developer who is always looking for something new to learn.

Updated on June 15, 2022

Comments

  • pgreen2
    pgreen2 almost 2 years

    I have a project which is packaged as an ear. For the past month or so system tests have been disabled. We turned them back on and have been fixing problems with failed tests and the build script. I have not been able to crack the latest problem:

    [ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.14.1:test (default-test) on project systemTest: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.14.1:test failed: A required class was missing while executing org.apache.maven.plugins:maven-surefire-plugin:2.14.1:test: org/junit/runner/notification/RunListener
    [ERROR] -----------------------------------------------------
    [ERROR] realm =    plugin>org.apache.maven.plugins:maven-surefire-plugin:2.14.1
    [ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
    [ERROR] urls[0] = file:/home/tomcat/.m2/repository/org/apache/maven/plugins/maven-surefire-plugin/2.14.1/maven-surefire-plugin-2.14.1.jar
    [ERROR] urls[1] = file:/home/tomcat/.m2/repository/org/apache/maven/surefire/surefire-junit47/2.14.1/surefire-junit47-2.14.1.jar
    [ERROR] urls[2] = file:/home/tomcat/.m2/repository/org/apache/maven/surefire/common-junit48/2.14.1/common-junit48-2.14.1.jar
    [ERROR] urls[3] = file:/home/tomcat/.m2/repository/org/apache/maven/surefire/common-junit4/2.14.1/common-junit4-2.14.1.jar
    [ERROR] urls[4] = file:/home/tomcat/.m2/repository/org/apache/maven/surefire/common-junit3/2.14.1/common-junit3-2.14.1.jar
    [ERROR] urls[5] = file:/home/tomcat/.m2/repository/org/apache/maven/surefire/surefire-grouper/2.14.1/surefire-grouper-2.14.1.jar
    [ERROR] urls[6] = file:/home/tomcat/.m2/repository/org/apache/maven/shared/maven-shared-utils/0.4/maven-shared-utils-0.4.jar
    [ERROR] urls[7] = file:/home/tomcat/.m2/repository/com/google/code/findbugs/jsr305/2.0.1/jsr305-2.0.1.jar
    [ERROR] urls[8] = file:/home/tomcat/.m2/repository/org/apache/maven/surefire/common-java5/2.14.1/common-java5-2.14.1.jar
    [ERROR] urls[9] = file:/home/tomcat/.m2/repository/org/apache/maven/surefire/maven-surefire-common/2.14.1/maven-surefire-common-2.14.1.jar
    [ERROR] urls[10] = file:/home/tomcat/.m2/repository/org/apache/maven/surefire/surefire-booter/2.14.1/surefire-booter-2.14.1.jar
    [ERROR] urls[11] = file:/home/tomcat/.m2/repository/org/codehaus/plexus/plexus-utils/1.5.1/plexus-utils-1.5.1.jar
    [ERROR] urls[12] = file:/home/tomcat/.m2/repository/org/apache/maven/reporting/maven-reporting-api/2.0.9/maven-reporting-api-2.0.9.jar
    [ERROR] urls[13] = file:/home/tomcat/.m2/repository/org/apache/commons/commons-lang3/3.1/commons-lang3-3.1.jar
    [ERROR] urls[14] = file:/home/tomcat/.m2/repository/org/apache/maven/surefire/surefire-api/2.14.1/surefire-api-2.14.1.jar
    [ERROR] urls[15] = file:/home/tomcat/.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]
    

    I can't figure out how org/junit/runner/notification/RunListener can't be found. The whole project is build with maven and junit is included as a test dependency.

    As far as we can tell, doing a full build works everywhere except on the build server. Second interesting point, on the build server, everything builds fine when system tests aren't included and system tests work fine when run by themselves. The problem only happens when the full project is built including the system tests.

    This is the relevant portion of the pom.xml for the system tests

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
            <includes>
                <include>com/crowncastle/test/*Test.class</include>
                <include>com/crowncastle/test/suite/*TestSuite.class</include>
            </includes>
            <additionalClasspathElements>
                <additionalClasspathElement>${basedir}${file.separator}..${file.separator}ear${file.separator}src${file.separator}main${file.separator}application${file.separator}APP-INF${file.separator}classes</additionalClasspathElement>
                <additionalClasspathElement>${basedir}${file.separator}..${file.separator}ff${file.separator}src${file.separator}main${file.separator}resources</additionalClasspathElement>
                <additionalClasspathElement>${basedir}${file.separator}..${file.separator}ff${file.separator}target${file.separator}classes</additionalClasspathElement>
                <additionalClasspathElement>${basedir}${file.separator}..${file.separator}ff${file.separator}target${file.separator}test-classes</additionalClasspathElement>
            </additionalClasspathElements>
            <forkMode>always</forkMode>
            <argLine>-Xmx1024m -XX:MaxPermSize=512m</argLine>
            <runOrder>alphabetical</runOrder>
            <redirectTestOutputToFile>true</redirectTestOutputToFile>
            <forkedProcessTimeoutInSeconds>900</forkedProcessTimeoutInSeconds>
        </configuration>
    </plugin>
    

    Update I thought perhaps there was an older version of junit hanging around that could be causing problems, so I ran mvn dependency:analyze and mvn dependency:tree but the only mention of junit is junit 4.10, which is the appropriate version.

    Update We were able to duplicate the problem on our test build server. I didn't mention before that the developer workstations run windows 8 and the build server is linux. So it could be a windows vs linux problem, but I don't see what.