Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

org.openrewrite.java.testing.junit5.JUnit4to5Migration should not add deprecated plugin dependency "junit-platform-surefire-provider" #534

Closed
gjd6640 opened this issue Jun 20, 2024 · 4 comments
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@gjd6640
Copy link

gjd6640 commented Jun 20, 2024

I'm loving the promise of this tooling so far. Here's one item that tripped me up today. Looks like it has a straightforward fix.

What version of OpenRewrite are you using?

I am using "rewrite-maven-plugin" version 5.34.1

How are you running OpenRewrite?

I am using the Maven plugin from the command line, and my project is a single module project.

mvn -e org.openrewrite.maven:rewrite-maven-plugin:run "-Drewrite.recipeArtifactCoordinates=org.openrewrite.recipe:rewrite-spring:RELEASE" "-Drewrite.activeRecipes=com.mycompany.OurCustomRecipes" "-Drewrite.configLocation=./rewrite.yml"

What is the smallest, simplest way to reproduce the problem?

Locate or generate a Maven project that's configured to use maven-surefire-plugin and JUnit 4 and run:

mvn -e org.openrewrite.maven:rewrite-maven-plugin:run "-Drewrite.activeRecipes=org.openrewrite.java.testing.junit5.JUnit4to5Migration"

Then kick off a build:

mvn test

How the issue presented

We ran recipe "org.openrewrite.java.spring.boot2.UpgradeSpringBoot_2_7" which runs several recipes including "org.openrewrite.java.spring.boot2.SpringBoot2JUnit4to5Migration" which in turn runs "org.openrewrite.java.testing.junit5.JUnit4to5Migration".

This produced this modified pom configuration:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>3.2.5</version>
    <dependencies>
      <dependency>
        <groupId>org.junit.platform</groupId>
        <artifactId>junit-platform-surefire-provider</artifactId>
        <version>1.1.0</version>
      </dependency>
    </dependencies>
  </plugin>

When I ran a standard "maven verify" build when it got to the maven-surefire-plugin's "test" goal the build failed after printing a stack trace containing this cause:

Caused by: java.lang.ClassNotFoundException: org.apache.maven.plugin.surefire.log.api.ConsoleLogger

Removing the "junit-platform-surefire-provider" plugin dependency from the pom.xml config snippet above fixed the issue.

This clause in source file junit5.yml seems to be the one that causes "junit-platform-surefire-provider" to be added as a plugin dependency under maven-surefire-plugin. Removing that "AddPluginDependency" recipe reference should do the trick.

Why is the change described above appropriate?

Per this issue and these release notes, library "junit-platform-surefire-provider" is deprecated since JUnit Jupiter 5 v5.3.0.

What is the full stack trace of any errors you encountered?

[INFO] --- maven-surefire-plugin:3.2.5:test (default-test) @ my-software-name-1_0 ---
[WARNING] Error injecting: org.apache.maven.plugin.surefire.SurefirePlugin
java.lang.NoClassDefFoundError: org/apache/maven/surefire/api/testset/TestSetFailedException
        at java.lang.Class.getDeclaredConstructors0(Native Method)
        at java.lang.Class.privateGetDeclaredConstructors(Class.java:2671)
        at java.lang.Class.getDeclaredConstructors(Class.java:2020)
        at com.google.inject.spi.InjectionPoint.forConstructorOf(InjectionPoint.java:245)
        at com.google.inject.internal.ConstructorBindingImpl.create(ConstructorBindingImpl.java:99)
        at com.google.inject.internal.InjectorImpl.createUninitializedBinding(InjectorImpl.java:658)
        at com.google.inject.internal.InjectorImpl.createJustInTimeBinding(InjectorImpl.java:882)
        at com.google.inject.internal.InjectorImpl.createJustInTimeBindingRecursive(InjectorImpl.java:805)
        at com.google.inject.internal.InjectorImpl.getJustInTimeBinding(InjectorImpl.java:282)
        at com.google.inject.internal.InjectorImpl.getBindingOrThrow(InjectorImpl.java:214)
        at com.google.inject.internal.InjectorImpl.getProviderOrThrow(InjectorImpl.java:1006)
        at com.google.inject.internal.InjectorImpl.getProvider(InjectorImpl.java:1038)
        at com.google.inject.internal.InjectorImpl.getProvider(InjectorImpl.java:1001)
        at com.google.inject.internal.InjectorImpl.getInstance(InjectorImpl.java:1051)
        at org.eclipse.sisu.space.AbstractDeferredClass.get(AbstractDeferredClass.java:48)
        at com.google.inject.internal.ProviderInternalFactory.provision(ProviderInternalFactory.java:81)
        at com.google.inject.internal.InternalFactoryToInitializableAdapter.provision(InternalFactoryToInitializableAdap
ter.java:53)
        at com.google.inject.internal.ProviderInternalFactory$1.call(ProviderInternalFactory.java:65)
        at com.google.inject.internal.ProvisionListenerStackCallback$Provision.provision(ProvisionListenerStackCallback.
java:115)
        at com.google.inject.internal.ProvisionListenerStackCallback$Provision.provision(ProvisionListenerStackCallback.
java:133)
        at com.google.inject.internal.ProvisionListenerStackCallback.provision(ProvisionListenerStackCallback.java:68)
        at com.google.inject.internal.ProviderInternalFactory.circularGet(ProviderInternalFactory.java:63)
        at com.google.inject.internal.InternalFactoryToInitializableAdapter.get(InternalFactoryToInitializableAdapter.ja
va:45)
        at com.google.inject.internal.InjectorImpl$2$1.call(InjectorImpl.java:1016)
        at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1092)
        at com.google.inject.internal.InjectorImpl$2.get(InjectorImpl.java:1012)
        at org.eclipse.sisu.inject.Guice4$1.get(Guice4.java:162)
        at org.eclipse.sisu.inject.LazyBeanEntry.getValue(LazyBeanEntry.java:81)
        at org.eclipse.sisu.plexus.LazyPlexusBean.getValue(LazyPlexusBean.java:51)
        at org.codehaus.plexus.DefaultPlexusContainer.lookup(DefaultPlexusContainer.java:263)
        at org.codehaus.plexus.DefaultPlexusContainer.lookup(DefaultPlexusContainer.java:255)
        at org.apache.maven.plugin.internal.DefaultMavenPluginManager.getConfiguredMojo(DefaultMavenPluginManager.java:5
19)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:121)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:154)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:146)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
        at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.
java:51)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:309)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:194)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:107)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:993)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:345)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:191)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: java.lang.ClassNotFoundException: org.apache.maven.surefire.api.testset.TestSetFailedException
        at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
        at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:271)
        at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:247)
        at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:239)
        ... 54 more
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------

Are you interested in contributing a fix to OpenRewrite?

I'm about to head out on vacation so no, not right now. If this goes unresolved, I may be able to submit a pull request in a few weeks. I am selfishly hoping someone familiar with the product picks this up while I'm out. :)

@gjd6640 gjd6640 added the bug Something isn't working label Jun 20, 2024
@timtebeek timtebeek added the good first issue Good for newcomers label Jun 20, 2024
@timtebeek
Copy link
Contributor

Indeed looks straightforward. Out of curiosity: what version of Maven are you using? I ask sauce there's a precondition on that recipe that should limit when it's applied.

@gjd6640
Copy link
Author

gjd6640 commented Jun 20, 2024 via email

@timtebeek
Copy link
Contributor

Ah yes that explains it then.. The recipe only runs for versions older than 3.5.4:

Not saying that's ideal here, but another option would be up upgrade your Maven version.

@timtebeek
Copy link
Contributor

Linking to the relevant earlier work here:

I'd think we're doing the right thing here: only adding that plugin on older versions of Maven.

Folks that want to prevent this can choose to run Update Maven wrapper first.

With that I think we can close this issue; but do let me know if I've misunderstood the need for junit-platform-surefire-provider on Maven 3.5.4 and below.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
Archived in project
Development

No branches or pull requests

2 participants