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

Caching of provider classpath with module-specific changes may break test bootstrapping in subsequent modules

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.22.2, 3.0.0-M3
    • 2.22.3, 3.0.0-M4
    • Maven Surefire Plugin
    • None

    Description

      I believe I've identified a bug in the caching that's performed by AbstractSurefireMojo. The problem that I am seeing is a failure to bootstrap Surefire:

       

      [ERROR] org.apache.maven.surefire.booter.SurefireBooterForkException: There was an error in the forked process
      [ERROR] java.lang.NoClassDefFoundError: org/junit/platform/launcher/core/LauncherFactory
      [ERROR] at org.apache.maven.plugin.surefire.booterclient.ForkStarter.fork(ForkStarter.java:657)
      [ERROR] at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:283)
      [ERROR] at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:246)
      [ERROR] at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeProvider(AbstractSurefireMojo.java:1161)
      [ERROR] at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeAfterPreconditionsChecked(AbstractSurefireMojo.java:1002)
      [ERROR] at org.apache.maven.plugin.surefire.AbstractSurefireMojo.execute(AbstractSurefireMojo.java:848)
      [ERROR] at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
      [ERROR] at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
      [ERROR] at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:154)
      [ERROR] at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:146)
      [ERROR] at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
      [ERROR] at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
      [ERROR] at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:56)
      [ERROR] at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
      [ERROR] at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:305)
      [ERROR] at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)
      [ERROR] at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)
      [ERROR] at org.apache.maven.cli.MavenCli.execute(MavenCli.java:954)
      [ERROR] at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
      [ERROR] at org.apache.maven.cli.MavenCli.main(MavenCli.java:192)
      [ERROR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      [ERROR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      [ERROR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      [ERROR] at java.lang.reflect.Method.invoke(Method.java:498)
      [ERROR] at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
      [ERROR] at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
      [ERROR] at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
      [ERROR] at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)

       

      This is in a module that uses Surefire and JUnit Jupiter 5.5:

       

      <dependencies>
      	<dependency>
      		<groupId>org.junit.jupiter</groupId>
      		<artifactId>junit-jupiter</artifactId>
      		<version>5.5.0</version>
      		<scope>test</scope>
      	</dependency>
      </dependencies>
      <build>
      	<plugins>
      		<plugin>
      			<groupId>org.apache.maven.plugins</groupId>
      			<artifactId>maven-surefire-plugin</artifactId>
      			<version>2.22.2</version>
      		</plugin>
      	</plugins>
      </build>
       

       

      Earlier in the reactor, another project is built which depends on junit-platform-launcher:

       

      <dependencies>
      	<dependency>
      		<groupId>org.junit.platform</groupId>
      		<artifactId>junit-platform-launcher</artifactId>
      		<version>1.5.0</version>
      	</dependency>
      	<dependency>
      		<groupId>org.junit.jupiter</groupId>
      		<artifactId>junit-jupiter</artifactId>
      		<version>5.5.0</version>
      		<scope>test</scope>
      	</dependency>
      </dependencies>
      <build>
      	<plugins>
      		<plugin>
      			<groupId>org.apache.maven.plugins</groupId>
      			<artifactId>maven-surefire-plugin</artifactId>
      			<version>2.22.2</version>
      		</plugin>
      	</plugins>
      </build>
      

      For the problem to occur, both projects have to be built in the same reactor. Building of the module which depends on junit-platform-launcher is causing some pollution that results in the other module failing to build.

      I believe I've tracked down the cause of this pollution to some caching that's performed by AbstractSurefireMojo:

      testClasspathWrapper.avoidArtifactDuplicates( providerArtifacts );
      
      
      Classpath providerClasspath = ClasspathCache.getCachedClassPath( providerName );
      if ( providerClasspath == null )
      {
          providerClasspath = ClasspathCache.setCachedClasspath( providerName, providerArtifacts );
      }
      

      The first line above removes the launcher artifact from providerArtifacts. These module-specific adjustments to the provider artifacts are then used to create the cached providerClasspath. When a subsequent module retrieves this cached classpath and uses it, the build fails as the launcher is missing.

      I have attached a zip which contains a minimal build that should reproduce the problem. You should see it fail when you run the verify goal.

      Attachments

        1. surefire-pollution-problem.zip
          5 kB
          Andy Wilkinson

        Activity

          People

            tibordigana Tibor Digana
            awilkinson Andy Wilkinson
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 40m
                40m