rewrite
rewrite copied to clipboard
Maven: Version resolution not working for dependency referencing older BOM
Hi,
I get an exception running a run
or dryRun
mojo with the rewrite-maven-plugin. The project is a multi-module project with a BOM for managing dependencies. If a dependency references an older version of the BOM the following exception occurs:
Caused by: org.openrewrite.maven.internal.MavenParsingException: No version provided for dependency org.springframework:spring-jdbc
at org.openrewrite.maven.tree.ResolvedPom.resolveDependencies (ResolvedPom.java:525)
at org.openrewrite.maven.tree.ResolvedPom.resolveDependencies (ResolvedPom.java:499)
at org.openrewrite.maven.tree.MavenResolutionResult.resolveDependencies (MavenResolutionResult.java:143)
at org.openrewrite.maven.MavenParser.parseInputs (MavenParser.java:111)
at org.openrewrite.Parser.parse (Parser.java:43)
at org.openrewrite.maven.MavenMojoProjectParser.parseMaven (MavenMojoProjectParser.java:302)
at org.openrewrite.maven.MavenMojoProjectParser.listSourceFiles (MavenMojoProjectParser.java:115)
at org.openrewrite.maven.AbstractRewriteMojo.listResults (AbstractRewriteMojo.java:210)
at org.openrewrite.maven.AbstractRewriteDryRunMojo.execute (AbstractRewriteDryRunMojo.java:56)
...
The dependency setup is roughly of this form:
org.openrewrite.maven:prj:jar:1.1 (dependencies managed by org.openrewrite.maven:bom:1.1)
\- org.openrewrite.maven:dep:jar:1.0:compile (dependencies managed by org.openrewrite.maven:bom:1.0)
\- org.springframework:spring-jdbc:jar:5.3.21:compile
+- org.springframework:spring-beans:jar:5.3.21:compile
+- org.springframework:spring-core:jar:5.3.21:compile
| \- org.springframework:spring-jcl:jar:5.3.21:compile
\- org.springframework:spring-tx:jar:5.3.21:compile
If the newer BOM does not manage the dependency org.springframework:spring-jdbc
the exception occurs.
As the project setup is a little bit weird, I created the repository https://github.com/thomaszub/rewrite-maven-bug for reproducing the issue:
- Execute
mvn clean install
in thefirst
directory - Execute in the
second
directory e.g.mvn -e org.openrewrite.maven:rewrite-maven-plugin:4.28.0-SNAPSHOT:dryRun -DactiveRecipes=org.openrewrite.java.RemoveUnusedImports
Kind regards
Thomas
@thomaszub Very much appreciate the detail and reproducible example. The issue you describe here is one of the most common parsing problems we are facing nightly trying to parse OSS projects, and this really shines a light on the specific cause.
@thomaszub Again, thank you for the detailed and reproducible example, it helped a lot!