openrewrite / rewrite-maven-plugin

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

Failed to resolve dependencies #862

Open philippe-granet opened 2 months ago

philippe-granet commented 2 months ago

What version of OpenRewrite are you using?

I am using latest maven plugin version v5.40.2

How are you running OpenRewrite?

I am using the Maven plugin in CLI

mvn org.openrewrite.maven:rewrite-maven-plugin:run -Drewrite.activeRecipes=org.openrewrite.maven.BestPractices

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

When I run mvn dependency:tree, I see my app depends on org.jetbrains:annotations:jar:24.1.0:compile:

mvn dependency:tree
...
[INFO] --------------------< org.openrewrite.test:module1 >--------------------
[INFO] Building module1 1.1-SNAPSHOT                                      [2/2]
[INFO]   from module1/pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- dependency:3.7.0:tree (default-cli) @ module1 ---
[INFO] org.openrewrite.test:module1:jar:1.1-SNAPSHOT
[INFO] \- org.openrewrite.test:starter-security-client-webmvc:jar:1.0:compile
[INFO]    \- org.openrewrite.test:starter-security-common:jar:1.0:compile
[INFO]       \- org.jetbrains:annotations:jar:24.1.0:compile

But when I run openrewrite on my app with this command:

mvn org.openrewrite.maven:rewrite-maven-plugin:run -Drewrite.activeRecipes=org.openrewrite.maven.BestPractices

it failed with this error: MavenDownloadingException: org.jetbrains:annotations failed. No version provided

To reproduce the problem, I create an exemple from my project. Unzip this (only poms inside): openrewrite-bug.zip

and run these commands:

cd lib
mvn clean install
cd ../app
mvn clean install
mvn dependency:tree
mvn org.openrewrite.maven:rewrite-maven-plugin:run -Drewrite.activeRecipes=org.openrewrite.maven.BestPractices

What did you expect to see?

No errors :-)

What did you see instead?

This error, it can't find version of org.jetbrains:annotations dependency:

[ERROR] Failed to execute goal org.openrewrite.maven:rewrite-maven-plugin:5.40.2:run (default-cli) on project module1: Failed to parse or resolve the Maven POM file or one of its dependencies; We can not reliably continue without this information.: Failed to parse or resolve the Maven POM file or one of its dependencies; We can not reliably continue without this information.
[ERROR] <?xml version="1.0" encoding="UTF-8"?>
[ERROR] <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
[ERROR]          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
[ERROR]     <modelVersion>4.0.0</modelVersion>
[ERROR]
[ERROR]     <parent>
[ERROR]         <groupId>org.openrewrite.test</groupId>
[ERROR]         <artifactId>app</artifactId>
[ERROR]         <version>1.1-SNAPSHOT</version>
[ERROR]     </parent>
[ERROR]
[ERROR]     <groupId>org.openrewrite.test</groupId>
[ERROR]     <artifactId>module1</artifactId>
[ERROR]     <packaging>jar</packaging>
[ERROR]
[ERROR]     <dependencies>
[ERROR]         <!--~~(org.jetbrains:annotations failed. No version provided)~~>--><dependency>
[ERROR]             <groupId>org.openrewrite.test</groupId>
[ERROR]             <artifactId>starter-security-client-webmvc</artifactId>
[ERROR]             <version>1.0</version>
[ERROR]             <scope>compile</scope>
[ERROR]         </dependency>
[ERROR]     </dependencies>
[ERROR] </project>
[ERROR] org.openrewrite.maven.MavenDownloadingExceptions: null
[ERROR]   org.openrewrite.maven.MavenDownloadingExceptions.append(MavenDownloadingExceptions.java:44)
[ERROR]   org.openrewrite.maven.tree.MavenResolutionResult.resolveDependencies(MavenResolutionResult.java:178)
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <args> -rf :module1

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

[INFO] Project [app] Resolving Poms...
[DEBUG] Downloaded org.openrewrite.test:java:1.0 from org.openrewrite.test:app:1.1-SNAPSHOT
[DEBUG] Downloaded org.openrewrite.test:pom:1.0 from org.openrewrite.test:app:1.1-SNAPSHOT
[DEBUG] Downloaded org.openrewrite.test:bom-pom:1.0 from org.openrewrite.test:app:1.1-SNAPSHOT
[DEBUG] Downloaded org.openrewrite.test:lib:1.0 from org.openrewrite.test:app:1.1-SNAPSHOT
[DEBUG] Downloaded org.openrewrite.test:all-bom:1.0 from org.openrewrite.test:app:1.1-SNAPSHOT
[DEBUG] Downloaded org.openrewrite.test:bom:1.0 from org.openrewrite.test:all-bom:1.0
[DEBUG] Downloaded org.openrewrite.test:commons-bom:1.0 from org.openrewrite.test:all-bom:1.0
[DEBUG] Downloaded org.openrewrite.test:libs-bom:1.0 from org.openrewrite.test:all-bom:1.0
[DEBUG] Downloaded org.openrewrite.test:starter-security-client-webmvc:1.0 from org.openrewrite.test:module1:1.1-SNAPSHOT
[DEBUG] Downloaded org.openrewrite.test:starter-security:1.0 from org.openrewrite.test:starter-security-client-webmvc:1.0
[DEBUG] Downloaded org.openrewrite.test:starters:1.0 from org.openrewrite.test:starter-security-client-webmvc:1.0
[DEBUG] Downloaded org.openrewrite.test:starter-security-common:1.0 from org.openrewrite.test:starter-security-client-webmvc:1.0
[DEBUG]
org.openrewrite.maven.MavenDownloadingExceptions
    at org.openrewrite.maven.MavenDownloadingExceptions.append (MavenDownloadingExceptions.java:44)
    at org.openrewrite.maven.tree.MavenResolutionResult.resolveDependencies (MavenResolutionResult.java:178)
    at org.openrewrite.maven.MavenParser.parseInputs (MavenParser.java:116)
    at org.openrewrite.Parser.parse (Parser.java:59)
    at org.openrewrite.maven.MavenMojoProjectParser.parseMaven (MavenMojoProjectParser.java:553)
    at org.openrewrite.maven.MavenMojoProjectParser.listSourceFiles (MavenMojoProjectParser.java:146)
    at org.openrewrite.maven.AbstractRewriteBaseRunMojo.loadSourceSet (AbstractRewriteBaseRunMojo.java:236)
    at org.openrewrite.maven.AbstractRewriteBaseRunMojo.listResults (AbstractRewriteBaseRunMojo.java:152)
    at org.openrewrite.maven.AbstractRewriteRunMojo.execute (AbstractRewriteRunMojo.java:64)
    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.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39)
    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:903)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:280)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:203)
    at jdk.internal.reflect.DirectMethodHandleAccessor.invoke (DirectMethodHandleAccessor.java:103)
    at java.lang.reflect.Method.invoke (Method.java:580)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:255)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:201)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:361)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:314)
    Suppressed: org.openrewrite.maven.MavenDownloadingException: org.jetbrains:annotations failed. No version provided
        at org.openrewrite.maven.tree.ResolvedPom.resolveDependencies (ResolvedPom.java:874)
        at org.openrewrite.maven.tree.ResolvedPom.resolveDependencies (ResolvedPom.java:845)
        at org.openrewrite.maven.tree.MavenResolutionResult.resolveDependencies (MavenResolutionResult.java:173)
        at org.openrewrite.maven.MavenParser.parseInputs (MavenParser.java:116)
        at org.openrewrite.Parser.parse (Parser.java:59)
        at org.openrewrite.maven.MavenMojoProjectParser.parseMaven (MavenMojoProjectParser.java:553)
        at org.openrewrite.maven.MavenMojoProjectParser.listSourceFiles (MavenMojoProjectParser.java:146)
        at org.openrewrite.maven.AbstractRewriteBaseRunMojo.loadSourceSet (AbstractRewriteBaseRunMojo.java:236)
        at org.openrewrite.maven.AbstractRewriteBaseRunMojo.listResults (AbstractRewriteBaseRunMojo.java:152)
        at org.openrewrite.maven.AbstractRewriteRunMojo.execute (AbstractRewriteRunMojo.java:64)
        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.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39)
        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:903)
        at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:280)
        at org.apache.maven.cli.MavenCli.main (MavenCli.java:203)
        at jdk.internal.reflect.DirectMethodHandleAccessor.invoke (DirectMethodHandleAccessor.java:103)
        at java.lang.reflect.Method.invoke (Method.java:580)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:255)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:201)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:361)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:314)
HelloDhero commented 2 months ago

Setting the parameter -Drewrite.pomCacheEnabled=false may solve the problem

philippe-granet commented 2 months ago

Same problem with -Drewrite.pomCacheEnabled=false parameter

timtebeek commented 2 months ago

Hi @philippe-granet ; Appreciate the level of detail in your report. Is there any way to reproduce the problem in a smaller example? Since 14 poms is quite a bit to wrap my head around. Ideally this is reproduced in a unit test. Note that we have mechanisms to reproduce this in unit tests in openrewrite/rewrite in our Assertions classes

https://github.com/openrewrite/rewrite/blob/a98d83d698dda9971c93a0767b7f85d5866f306d/rewrite-java/src/main/java/org/openrewrite/java/Assertions.java#L131-L137

https://github.com/openrewrite/rewrite/blob/50cb39c5da3362d1eed4d6ec4562177f007becb0/rewrite-maven/src/main/java/org/openrewrite/maven/Assertions.java#L45-L70

philippe-granet commented 2 months ago

@timtebeek I have reproduce the problem with only 3 simples poms: openrewrite-bug.zip

Jamel-jun commented 1 week ago

I'm running into this issue as well, I'm a multi-module project, follow this doc :https://docs.openrewrite.org/running-recipes/multi-module-maven When I add skipMavenParsing = true, everything works fine, but it seems that the maven recipe doesn't work.

cleankod commented 1 day ago

Do you happen to have any news on this one, by chance? I'm doing a huge tech stack migration, and having this fix would help significantly. 🙏