openrewrite / rewrite-java-dependencies

OpenRewrite recipes for managing Java dependencies.
Apache License 2.0
12 stars 9 forks source link

Add validation to `ChangeDependency`, so it checks that either group or artifact is different from the old. #55

Open timtebeek opened 10 months ago

timtebeek commented 10 months ago

What problem are you trying to solve?

the Change*Dependency… recipes are specifically for changing to a different dependency (as the name implies, doh!). The fact that it has a newVersion parameter tripped me up. I see UpgradeDependencyVersion does what I expected. A reference from Change… to Upgrade may be helpful. In fact I see Change… being used supposedly to perform an upgrade (judging from the recipe docs) when perhaps an Upgrade… was intended. If the old and the new G+A are identical and newVersion is specified, then it's not a move/change and likely should be an Upgrade.

Describe the solution you'd like

Add validation to ChangeDependency, so it checks that either group or artifact is different from the old. This would apply to both the rewrite-java-dependency recipe, as well as the two rewrite-maven recipes.

Have you considered any alternatives or workarounds?

use a yaml rewrite recipe to change existing recipies (like the ones above) to use Upgrade if the new and old G+A are the same. use a yaml rewrite recipe to change existing recipies (like the ones above) to use Upgrade if the new and old G+A are the same.

Additional context

As suggested on OSS Slack by @tobli

timtebeek commented 10 months ago

Here are some examples I found: