Uploaded image for project: 'Maven Surefire'
  1. Maven Surefire
  2. SUREFIRE-1632

ClassNotFoundException, multi-module Maven project, forkCount > 1

    XMLWordPrintableJSON

    Details

      Description

      Base configuration:

      • Windows 10
      • Maven 3.6.0
      • Mixed Java 8 and Scala 2.11.8
      • JMockit¬†

      I'm trying update my SureFire configuration in a multi-module project from:

      • SureFire 2.20
      • JUnit 5.01

      to:

      • SureFire 2.22.1
      • JUnit 5 1.3.2

      This is the SureFire configuration I've come up with:

      <plugin>
      	<groupId>org.apache.maven.plugins</groupId>
      	<artifactId>maven-surefire-plugin</artifactId>
      	<version>2.22.1</version>
      	<configuration>
      		<forkCount>2</forkCount>
      		<threadCount>2</threadCount>
      		<reuseForks>true</reuseForks>
      		
      		<!-- The '-XX:-TieredCompilation -Xint' args are used to compensate for a JDK defect that -->
      		<!-- impacts the performance of the JMockit API.  Oracle will add the fix to Java 9, so   -->
      		<!-- when the application is upgraded to use that version, these settings should be       -->
      		<!-- revisited.                                                                           -->
      		<!-- (https://groups.google.com/forum/#!msg/jmockit-users/MCm97zsjjd4/ZzSu9gusu8IJ)       -->
      		<!-- Sets the VM argument line used when unit tests are run. -->
      		<argLine>-XX:-TieredCompilation -Xint -javaagent:${org.jmockit:jmockit:jar}	@{surefireArgLine} -server</argLine>
      		<includes>
      			<include>**/*Suite.class</include>
      			<include>**/*Test.class</include>
      			<include>**/*Tests.class</include>
      			<include>**/*Spec.class</include>
      			<include>**/*Specs.class</include>
      		</includes>
      		<excludes>
      			<exclude>**/*ITest.class</exclude>
      		</excludes>
      		<properties>
      			<configurationParameters>
      				junit.jupiter.execution.parallel.enabled=true
      				junit.jupiter.execution.parallel.config.strategy=dynamic
      			</configurationParameters>
      			<property>
      				<name>listener</name>
      				<value>org.evosuite.runtime.InitializingListener</value>
      			</property>
      		</properties>
      	</configuration>
      </plugin>
      

      When I run the multi-module build (mvn test), the second module fails with the error:

      [INFO] ------------------------------------------------------------------------
      [INFO] BUILD FAILURE
      [INFO] ------------------------------------------------------------------------
      [INFO] Total time: 05:52 min
      [INFO] Finished at: 2019-01-30T13:09:43-05:00
      [INFO] ------------------------------------------------------------------------
      [ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.1:test (default-test) on project guardians: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.22.1:test failed: A required class was missing while executing org.apache.maven.plugins:maven-surefire-plugin:2.22.1:test: org/apache/maven/surefire/report/ConsoleOutputReceiver
      [ERROR] -----------------------------------------------------
      [ERROR] realm = plugin>org.apache.maven.plugins:maven-surefire-plugin:2.22.1
      [ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
      [ERROR] urls[0] = file:/C:/Users/starlord/.m2/repository/org/apache/maven/plugins/maven-surefire-plugin/2.22.1/maven-surefire-plugin-2.22.1.jar
      [ERROR] urls[1] = file:/C:/Users/starlord/.m2/repository/org/apache/maven/surefire/maven-surefire-common/2.22.1/maven-surefire-common-2.22.1.jar
      [ERROR] urls[2] = file:/C:/Users/starlord/.m2/repository/org/apache/maven/plugin-tools/maven-plugin-annotations/3.5.2/maven-plugin-annotations-3.5.2.jar
      [ERROR] urls[3] = file:/C:/Users/starlord/.m2/repository/org/apache/maven/surefire/surefire-api/2.22.1/surefire-api-2.22.1.jar
      [ERROR] urls[4] = file:/C:/Users/starlord/.m2/repository/org/apache/maven/surefire/surefire-logger-api/2.22.1/surefire-logger-api-2.22.1.jar
      [ERROR] urls[5] = file:/C:/Users/starlord/.m2/repository/org/apache/maven/surefire/surefire-booter/2.22.1/surefire-booter-2.22.1.jar
      [ERROR] urls[6] = file:/C:/Users/starlord/.m2/repository/org/codehaus/plexus/plexus-utils/1.5.15/plexus-utils-1.5.15.jar
      [ERROR] urls[7] = file:/C:/Users/starlord/.m2/repository/junit/junit/4.12/junit-4.12.jar
      [ERROR] urls[8] = file:/C:/Users/starlord/.m2/repository/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar
      [ERROR] urls[9] = file:/C:/Users/starlord/.m2/repository/backport-util-concurrent/backport-util-concurrent/3.1/backport-util-concurrent-3.1.jar
      [ERROR] urls[10] = file:/C:/Users/starlord/.m2/repository/org/codehaus/plexus/plexus-interpolation/1.11/plexus-interpolation-1.11.jar
      [ERROR] urls[11] = file:/C:/Users/starlord/.m2/repository/org/slf4j/slf4j-jdk14/1.5.6/slf4j-jdk14-1.5.6.jar
      [ERROR] urls[12] = file:/C:/Users/starlord/.m2/repository/org/slf4j/jcl-over-slf4j/1.5.6/jcl-over-slf4j-1.5.6.jar
      [ERROR] urls[13] = file:/C:/Users/starlord/.m2/repository/org/apache/maven/reporting/maven-reporting-api/3.0/maven-reporting-api-3.0.jar
      [ERROR] urls[14] = file:/C:/Users/starlord/.m2/repository/org/sonatype/plexus/plexus-sec-dispatcher/1.3/plexus-sec-dispatcher-1.3.jar
      [ERROR] urls[15] = file:/C:/Users/starlord/.m2/repository/org/sonatype/plexus/plexus-cipher/1.4/plexus-cipher-1.4.jar
      [ERROR] urls[16] = file:/C:/Users/starlord/.m2/repository/org/codehaus/plexus/plexus-java/0.9.10/plexus-java-0.9.10.jar
      [ERROR] urls[17] = file:/C:/Users/starlord/.m2/repository/org/ow2/asm/asm/6.2/asm-6.2.jar
      [ERROR] urls[18] = file:/C:/Users/starlord/.m2/repository/com/thoughtworks/qdox/qdox/2.0-M8/qdox-2.0-M8.jar
      [ERROR] Number of foreign imports: 1
      [ERROR] import: Entry[import from realm ClassRealm[maven.api, parent: null]]
      [ERROR] 
      [ERROR] -----------------------------------------------------
      [ERROR] : org.apache.maven.surefire.report.ConsoleOutputReceiver
      [ERROR] -> [Help 1]

      though if I build the module by itself, everything passes. I repeated the steps in debug mode and saw the missing dependency wasn't being added to the in-process classpath during the multi-module build:

      • [DEBUG] in-process(compact) classpath: surefire-junit-platform-2.22.1.jar surefire-logger-api-2.22.1.jar maven-surefire-common-2.22.1.jar

      yet it was on the single module build:

      • [DEBUG] in-process(compact) classpath: surefire-junit-platform-2.22.1.jar surefire-logger-api-2.22.1.jar maven-surefire-common-2.22.1.jar surefire-api-2.22.1.jar

      Lastly, I can see the AbstractSureFireMojo.resolveArtifact method adding the surefire-logger-api-2.22.1.jar to the classpath during a single module build:

      [DEBUG] dummy:dummy:jar:1.0 (selected for null)
      [DEBUG] org.apache.maven.surefire:surefire-booter:jar:2.22.1:compile (selected for compile)
      [DEBUG] org.apache.maven.surefire:surefire-api:jar:2.22.1:compile (selected for compile)
      [DEBUG] org.apache.maven.surefire:surefire-logger-api:jar:2.22.1:compile (selected for compile)
      [DEBUG] Adding to surefire booter test classpath: C:\Users\starlord\.m2\repository\org\apache\maven\surefire\surefire-booter\2.22.1\surefire-booter-2.22.1.jar Scope: compile
      [DEBUG] Adding to surefire booter test classpath: C:\Users\starlord\.m2\repository\org\apache\maven\surefire\surefire-api\2.22.1\surefire-api-2.22.1.jar Scope: compile
      [DEBUG] Adding to surefire booter test classpath: C:\Users\starlord\.m2\repository\org\apache\maven\surefire\surefire-logger-api\2.22.1\surefire-logger-api-2.22.1.jar Scope: compile

      but not the multi-module build.

      I think this issue is similar to SUREFIRE-1520, though I am not using the deprecated JUnit 5 SureFire provider. I've set the priority as minor because I can work around it by manually adding the surefire-api-2.22.1.jar dependency to my parent POM. I can also use the default forkCount of one, though the build is of course much slower.

      If you see something I could do better in my configuration, please let me know.

        Attachments

          Activity

            People

            • Assignee:
              tibordigana Tibor Digana
              Reporter:
              jkaibjr Jim Kaib
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: