2

I have an existing project, want to upgrade test cases to Junit5. Tried to run below command

mvn -U org.openrewrite.maven:rewrite-maven-plugin:run -Drewrite.recipeArtifactCoordinates=org.openrewrite.recipe:rewrite-testing-frameworks:RELEASE -Drewrite.activeRecipes=org.openrewrite.java.testing.junit5.JUnit5BestPractices -e

This is first time I am trying to use open rewrite tool

    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:375)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:351)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:171)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:163)
    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:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:298)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:960)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:293)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:196)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution default-cli of goal org.openrewrite.maven:rewrite-maven-plugin:4.43.0:run failed: java.lang.NoSuchMethodError: org.openrewrite.java.search.UsesType.<init>(Ljava/lang/String;)V
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:148)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:370)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:351)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:171)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:163)
    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:56)

Nagendra Busam
  • 235
  • 1
  • 5
  • 19

1 Answers1

1

Might I suggest connecting to the OpenRewrite Slack channel. See https://docs.openrewrite.org/. It looks as if you get a much faster answer there. Yesterday a new version was released with a backwards incompatibility in it. which causes your error.

From the slacks: rewrite 7.39.0 introduced a change to UsesType and requires adding a boolean.The equivalent to UsesType(type) is either UsesType(type, {false or null}). Apologies for the inconvenience!

You should be fine with the latest version rewrite-maven-plugin 4.43.0 (which retrieves iirc 7.39.x) rewrite-migrate-java 1.19.0

PS I had the same error on Friday.

Jan B
  • 11
  • 2
  • Thank you Jan B, unfortunately I could not access slack from my office network. Do you have proper pom configuration somewhere which I can reuse? – Nagendra Busam Apr 05 '23 at 18:15
  • For the core openRewrite recipes no extra dependency is needed. Maven setup: https://docs.openrewrite.org/running-recipes/getting-started For special recipes like testing a dependency is needed: your exact setup: https://docs.openrewrite.org/reference/recipes/java/testing/junit5/junit5bestpractices I also use the Java 11 and Java 17 recipes: https://docs.openrewrite.org/running-recipes/popular-recipe-guides/migrate-to-java-17 – Jan B Apr 05 '23 at 21:33
  • Just created a SO account and apparently my comments can't be long. Hence can't post my setup. BUT my setup is in principle the core setup enhanced with the two dependencies for Migrate 11/17 and your JUnit5BestPractices recipe – Jan B Apr 05 '23 at 21:43