openrewrite / rewrite

Automated mass refactoring of source code.
https://docs.openrewrite.org
Apache License 2.0
2.03k stars 300 forks source link

Error: No version provided for dependency org.springframework:spring-core (managed dependency) #1422

Closed josemariavillar closed 2 years ago

josemariavillar commented 2 years ago

Good morning,

With version 7.19.0 there is an error when parsing the original maven file because the parent POM contains an unversioned dependencyManagement.

[INFO] --- rewrite-maven-plugin:4.20.0:dryRun (default-cli) @ test-project ---
[INFO] Using active recipe(s) [com.yourorg.UpgradePom]
[INFO] Using active styles(s) []
[INFO] Validating active recipes...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  25.989 s
[INFO] Finished at: 2022-03-02T10:26:33+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.openrewrite.maven:rewrite-maven-plugin:4.20.0:dryRun (default-cli) on project test-project: Execution default-cli of goal org.openrewrite.maven:rewrite-maven-plugin:4.20.0:dryRun failed: No version
 provided for dependency org.springframework:spring-core -> [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/PluginExecutionException

This problem was solved in version 7.16.0 (https://github.com/openrewrite/rewrite/issues/1084) , but since version 7.18.2 (https://github.com/openrewrite/rewrite/issues/1406) it is happening again.

Attached is an example test, where the problem is reproduced.

Child project: https://github.com/josemariavillar/test_project/tree/no-version-provided Parent project: https://github.com/josemariavillar/test-project-parent/tree/no-version-provided

traceyyoshima commented 2 years ago

Hi @josemariavillar, thanks for the report, we'll take a look!

mpatnode commented 2 years ago

@josemariavillar Having a similar problem. Can you tell me what version of the maven plugin maps back to 7.16.0?

mpatnode commented 2 years ago

-DskipMavenParsing=true saved me here.

josemariavillar commented 2 years ago

@mpatnode the version of the plugin that includes the 7.16.0 version of rewrite is 4.16.0.

Regarding the workaround you comment, unfortunately in my case, I can't use skipMavenParsing to true as it causes no recipe to be executed in the pom.xml file. What I do think would be very useful, is if you could skip the parsing of Maven transitive poms which is where most of the problems occur.

mpatnode commented 2 years ago

@josemariavillar > I can't use skipMavenParsing to true as it causes no recipe to be executed in the pom.xml file That wasn't my experience. It does skip editing the pom.xml file (the failure happens when parsing a new generated version) but it still edited all my Java files.

josemariavillar commented 2 years ago

@mpatnode At least in version 4.20 the tests I have done with this parameter set to true does not run any maven rules on the pom file. @tkvangorder, could this be an issue?

tkvangorder commented 2 years ago

@josemariavillar yes, if you skip maven parsing, there will be no ability for maven-based recipes to transform maven build files. The commit I made last night should fix this problem, I just need to get all of the tests passing so the 7.20.0-SNAPSHOT is published to the snapshot repo.

josemariavillar commented 2 years ago

Great, @tkvangorder thank you very much for your great work! I validate it and let you know

radcortez commented 2 years ago

I'm experiencing the same issue even with the latest SNAPSHOT build. I've tried it in this project: https://github.com/smallrye/smallrye-reactive-messaging, but some dependencies are causing issues.

One issue is with an inactive profile dependency provided by Weld, which fails with a No version provided for dependency javax.xml.ws:jaxws-api: https://github.com/weld/core/blob/3.1.9.Final/impl/pom.xml#L167-L178

Another one is No version provided for dependency io.netty:netty-transport-native-epoll, which seems to be caused by this: https://github.com/apache/activemq-artemis/blob/2.19.0/artemis-server/pom.xml#L129-L138

tkvangorder commented 2 years ago

@radcortez , In talking with @josemariavillar , he noted that I had not bumped the maven plugin to the latest snapshot of rewrite. I just applied this change this morning, can you try using the new snapshot version and see if that makes a difference?

https://github.com/openrewrite/rewrite-maven-plugin/commit/5993bb35f324cbb111b10309fc7dba69bf7f8c1f

Thanks

radcortez commented 2 years ago

Thanks for the quick response.

Yes, I've noticed that. I did the build locally and updated it myself.

radcortez commented 2 years ago

BTW to clarify, I did try before with a local build and with the SNAPSHOT manually update. Anyway, just to make sure I did try again today and the issue persists. Thanks!

tkvangorder commented 2 years ago

Thanks @radcortez , I will take a look today.

tkvangorder commented 2 years ago

@radcortez I have an update on the first issue you are having with the jaxws-api dependency in the profile.

If I clone the weld repo, check out the tag 3.1.9.Final and then attempt to run maven with that profile active, maven will also report this as an error.

mvn validate -Pjavax.xml.ws

[INFO] Scanning for projects...
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[ERROR] 'dependencies.dependency.version' for javax.xml.ws:jaxws-api:jar is missing. @ line 173, column 29

I also understand that this is completely out of your control since this happens in a transitively included pom. We take the approach of failing fast when we encounter an invalid maven build file, but maybe we need to relax this constraint and instead log a warning. I will get back to you shortly

tkvangorder commented 2 years ago

@radcortez I have found and fixed the issue with the netty dependencies with #1454

Thank you for the detailed error descriptions, they really help.

radcortez commented 2 years ago

I also understand that this is completely out of your control since this happens in a transitively included pom. We take the approach of failing fast when we encounter an invalid maven build file, but maybe we need to relax this constraint and instead log a warning. I will get back to you shortly

Thanks. Maybe an option could be to ignore inactive profiles?

@radcortez I have found and fixed the issue with the netty dependencies with #1454

Great. Thanks. I'll workaround the Weld issue and check if there is any other problem with the rest of the dependencies.

tkvangorder commented 2 years ago

@radcortez I have fixed the issue you were seeing with weld. Please see #1462

radcortez commented 2 years ago

Thanks. I'll give it a try!

radcortez commented 2 years ago

Seems to work, thank you :)