openrewrite / rewrite-maven-plugin

OpenRewrite's Maven plugin.
https://openrewrite.github.io/rewrite-maven-plugin/plugin-info.html
Apache License 2.0
127 stars 67 forks source link

Please give insight on how to best debug `Recipes not found` for user supplied recipe that is in user specified dependency #776

Closed scottmarlow closed 2 months ago

scottmarlow commented 2 months ago

Please advise how I can gain insight into why the Recipes not found is thrown for a recipe that is contained in an artifact specified as a rewrite-maven-plugin configuration dependency.

So far, I tried setting a debugger breakpoint in org.openrewrite.config.Environment#activateRecipes which didn't seem to process the tck.jakarta.platform:tck-rewrite-tools:1.0-SNAPSHOT dependency that is included in the rewrite-maven-plugin configuration. Could this be caused by a missing dependency/class not found issue? Or something else?

This is a work in progress effort to refactor the Jakarta EE 11 Platform TCK tests via the https://github.com/jakartaee/platform-tck/tree/tckrefactor which we would like to complete in 2024.

I am using:

I am using the Maven plugin in a module that is part of a multi-module project.

Can you share your configuration so that we can rule out any configuration issues?

Please see https://github.com/scottmarlow/jakartaee-tck/blob/rewritejpa/jpa/pom.xml#L137

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

I will update this to include the needed steps.

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

[ERROR] Failed to execute goal org.openrewrite.maven:rewrite-maven-plugin:5.28.0:runNoFork (default-cli) on project persistence-tck: Execution default-cli of goal org.openrewrite.maven:rewrite-maven-plugin:5.28.0:runNoFork failed: Recipes not found: tck.jakarta.platform.rewrite.AddArquillianDeployMethod -> [Help 1] org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.openrewrite.maven:rewrite-maven-plugin:5.28.0:runNoFork (default-cli) on project persistence-tck: Execution default-cli of goal org.openrewrite.maven:rewrite-maven-plugin:5.28.0:runNoFork failed: Recipes not found: tck.jakarta.platform.rewrite.AddArquillianDeployMethod at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:333) at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:316) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:212) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:174) at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:75) at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:162) at org.apache.maven.buildcache.BuildCacheMojosExecutionStrategy.execute (BuildCacheMojosExecutionStrategy.java:132) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:159) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:73) at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:53) at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:118) at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:261) at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:173) at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:101) at org.apache.maven.cli.MavenCli.execute (MavenCli.java:906) at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:283) at org.apache.maven.cli.MavenCli.main (MavenCli.java:206) at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method) at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:77) at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke (Method.java:568) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:283) at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:226) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:407) at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:348) Caused by: org.apache.maven.plugin.PluginExecutionException: Execution default-cli of goal org.openrewrite.maven:rewrite-maven-plugin:5.28.0:runNoFork failed: Recipes not found: tck.jakarta.platform.rewrite.AddArquillianDeployMethod at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:133) at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:328) at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:316) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:212) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:174) at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:75) at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:162) at org.apache.maven.buildcache.BuildCacheMojosExecutionStrategy.execute (BuildCacheMojosExecutionStrategy.java:132) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:159) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:73) at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:53) at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:118) at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:261) at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:173) at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:101) at org.apache.maven.cli.MavenCli.execute (MavenCli.java:906) at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:283) at org.apache.maven.cli.MavenCli.main (MavenCli.java:206) at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method) at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:77) at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke (Method.java:568) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:283) at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:226) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:407) at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:348) Caused by: org.openrewrite.RecipeException: Recipes not found: tck.jakarta.platform.rewrite.AddArquillianDeployMethod at org.openrewrite.config.Environment.activateRecipes (Environment.java:154) at org.openrewrite.maven.AbstractRewriteMojo.listResults (AbstractRewriteMojo.java:216) at org.openrewrite.maven.AbstractRewriteRunMojo.execute (AbstractRewriteRunMojo.java:62) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:126) at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:328) at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:316) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:212) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:174) at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:75) at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:162) at org.apache.maven.buildcache.BuildCacheMojosExecutionStrategy.execute (BuildCacheMojosExecutionStrategy.java:132) at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:159) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:73) at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:53) at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:118) at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:261) at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:173) at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:101) at org.apache.maven.cli.MavenCli.execute (MavenCli.java:906) at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:283) at org.apache.maven.cli.MavenCli.main (MavenCli.java:206) at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method) at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:77) at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke (Method.java:568) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:283) at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:226) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:407) at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:348) [ERROR]

Are you interested in contributing a fix to OpenRewrite?

scottmarlow commented 2 months ago

https://www.linkedin.com/pulse/how-build-megazord-making-godfather-java-tests-young-again-daniel-sshgf/ has some related context with regard to the ^ effort.

timtebeek commented 2 months ago

Hi @scottmarlow and welcome to the project! Happy to help you with this migration; feel free to drop into our Slack if you want a more synchronous way to reach me.

Had a brief look, at it appears you've configured AddArquillianDeployMethod as your active recipe, but looking at the implementation that extends JavaIsoVisitor, instead of org.openrewrite.Recipe.

AddArquillianDeployMethod<ExecutionContext> extends JavaIsoVisitor<ExecutionContext>

You'll likely want to create a recipe that returns that visitor instead, and configure that for your recipe runs. Let me know if you'd like more guidance than just that feedback, and I'll see what I can fit in.

Glad to see you're using OpenRewrite already; if you'd like we can also deploy your recipes to app.moderne.io, such that you can run them at scale more easily; likely something that'll help once you're further along. Our Moderne CLI and IntelliJ might also help you iterate more quickly in recipe development; happy to get you up to speed on all of those.

timtebeek commented 2 months ago

Separately had a brief look on of we can provide a more helpful error message when a recipe is not found, but it's instead a non-recipe class as was the case here. The relevant code is here: https://github.com/openrewrite/rewrite/blob/d5071a5f0fda751f6a5f4f075c6dedfd81776410/rewrite-core/src/main/java/org/openrewrite/config/Environment.java#L136-L155

The challenge there is the listRecipes calls through to a ResourceLoader interface that abstracts over the various ways recipes can be loaded from classpath & yaml files, both in OSS Maven/Gradle plugins and the Moderne platform & CLI. That means it's not easy to detect that a class might be found, but is not of the correct type.

I'm hoping this type of issue is rare, and that recent updates to the docs and providing a rewrite-recipe-starter would prevent this type of issue in the future.

In any case I'll gladly get you up and running with an openrewrite/rewrite-jakartaee module if that helps all of us collaborate on recipes, and deploy those to the Moderne platform. We already support running recipes on some 38 Jakarta EE repositories there, and can help you track progress towards goals through our DevCenter: https://app.moderne.io/devcenter/Jakarta%20EE

With that I think we can close this issue, although I'll monitor any responses to build out this collaboration.

scottmarlow commented 2 months ago

I'm hoping this type of issue is rare, and that recent updates to the docs and providing a rewrite-recipe-starter would prevent this type of issue in the future.

+1

In any case I'll gladly get you up and running with an openrewrite/rewrite-jakartaee module if that helps all of us collaborate on recipes, and deploy those to the Moderne platform. We already support running recipes on some 38 Jakarta EE repositories there, and can help you track progress towards goals through our DevCenter: https://app.moderne.io/devcenter/Jakarta%20EE

I'm just now reading your comments from a few months ago on https://www.linkedin.com/pulse/how-build-megazord-making-godfather-java-tests-young-again-daniel-sshgf about ^ and looked at the jakartaee recipes on the Moderne which look great for user applications. Those jakartaee recipes should be repeatably useful, however we are looking to do a one time (automated) rewrite of the Jakarta EE Platform TCK tests in the https://github.com/jakartaee/platform-tck/tree/tckrefactor branch. We have already switched from Apache Ant to building with Apache Maven but still need to switch from the Java Test Harness (predates JUnit framework). This topic probably deserves a Slack thread discussion, so I will start one there.