Skip to content

ChangeDependencyGroupIdAndArtifactId does not update properties in parent pom#5815

Merged
timtebeek merged 20 commits intomainfrom
1374-dependency-references-version-in-parent-during-change-dependency
Aug 11, 2025
Merged

ChangeDependencyGroupIdAndArtifactId does not update properties in parent pom#5815
timtebeek merged 20 commits intomainfrom
1374-dependency-references-version-in-parent-during-change-dependency

Conversation

@steve-aom-elliott
Copy link
Copy Markdown
Contributor

@steve-aom-elliott steve-aom-elliott commented Jul 28, 2025

What's changed?

The ChangeDependencyGroupIdAndArtifactId recipe can also use properties defined a parent pom.

What's your motivation?

Having version's defined in a parent pom is quite common. Other recipes like UpgradeDependencyVersion do already support this.

Additional context

Most of the changes consist of moving all the visitor code into the scanning phase, so we can determine which actions have to be done (whether it is changing properties, creating, remove or changing values). Then in the actual visitor phase we apply these changes accordingly.

Checklist

  • I've added unit tests to cover both positive and negative cases
  • I've read and applied the recipe conventions and best practices
  • I've used the IntelliJ IDEA auto-formatter on affected files

github-actions[bot]

This comment was marked as outdated.

@jevanlingen jevanlingen changed the title Version property in parent pom.xml that is not referenced in parent pom.xml is not updated when child dependency runs ChangeDependency ChangeDependencyGroupIdAndArtifactId does not update properties in parent pom Jul 31, 2025
github-actions[bot]

This comment was marked as outdated.

jevanlingen and others added 3 commits July 31, 2025 11:37
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
github-actions[bot]

This comment was marked as outdated.

@openrewrite openrewrite deleted a comment from github-actions bot Jul 31, 2025
github-actions[bot]

This comment was marked as outdated.

@openrewrite openrewrite deleted a comment from github-actions bot Jul 31, 2025
@jevanlingen jevanlingen marked this pull request as ready for review July 31, 2025 10:10
github-actions[bot]

This comment was marked as outdated.

github-actions[bot]

This comment was marked as outdated.

@openrewrite openrewrite deleted a comment from github-actions bot Jul 31, 2025
github-actions[bot]

This comment was marked as outdated.

@openrewrite openrewrite deleted a comment from github-actions bot Jul 31, 2025
@openrewrite openrewrite deleted a comment from github-actions bot Jul 31, 2025
@jevanlingen jevanlingen moved this from In Progress to Ready to Review in OpenRewrite Jul 31, 2025
@jevanlingen jevanlingen requested a review from Laurens-W August 1, 2025 06:19
@steve-aom-elliott
Copy link
Copy Markdown
Contributor Author

There's obviously a lot of changes, but in general it seems to be doing what it needs to.

@jevanlingen jevanlingen requested a review from timtebeek August 5, 2025 07:18
@timtebeek
Copy link
Copy Markdown
Member

As discussed with Jonathan I'll do a last pass over this one before we merge, since we already use the same pattern elsewhere and can resolve the immediate need with this change.

In the near term we'd want to revisit this recipe and others like it to extract traits, as we're increasingly seeing complicated logic in each of the Maven (and Gradle) dependency recipes, with subtle variations that might best to pulled out of the recipes and handled once.

@timtebeek timtebeek merged commit faf51f5 into main Aug 11, 2025
2 checks passed
@timtebeek timtebeek deleted the 1374-dependency-references-version-in-parent-during-change-dependency branch August 11, 2025 09:52
@github-project-automation github-project-automation bot moved this from Ready to Review to Done in OpenRewrite Aug 11, 2025
Jenson3210 added a commit that referenced this pull request Aug 12, 2025
timtebeek added a commit that referenced this pull request Aug 12, 2025
…ties in parent pom (#5815) (#5903)

* Revert "`ChangeDependencyGroupIdAndArtifactId` does not update properties in parent pom (#5815)"

This reverts commit faf51f5.

* Minimize diff in revert

---------

Co-authored-by: Tim te Beek <tim@moderne.io>
dcsekar pushed a commit to dcsekar/rewrite that referenced this pull request Aug 18, 2025
…parent pom (openrewrite#5815)

* Adding example showcasing problem

* Impl

* Apply suggestion from @github-actions[bot]

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Polish

* Polish

* Polish

* Polish

* Polish

* Polish

* Fix retain versions for UpgradeDependencyVersion

* Polish

* Polish

* Polish

* Polish

* Polish

* Minor polish

---------

Co-authored-by: lingenj <jacob.van.lingen@moderne.io>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Tim te Beek <tim@moderne.io>
dcsekar pushed a commit to dcsekar/rewrite that referenced this pull request Aug 18, 2025
…ties in parent pom (openrewrite#5815) (openrewrite#5903)

* Revert "`ChangeDependencyGroupIdAndArtifactId` does not update properties in parent pom (openrewrite#5815)"

This reverts commit faf51f5.

* Minimize diff in revert

---------

Co-authored-by: Tim te Beek <tim@moderne.io>
MBoegers added a commit that referenced this pull request Jan 29, 2026
…parent POMs

Convert `ChangeDependencyGroupIdAndArtifactId` from `Recipe` to
`ScanningRecipe` so that version properties defined in parent POMs
are updated when the dependency referencing that property is in a
child POM.

The scanner phase identifies version properties inherited from parent
POMs and records which source file defines each property. The visitor
phase then applies property updates when visiting those parent POM
files. All existing visitor logic is preserved unchanged, avoiding
the recipe-chaining issues that caused the previous attempt (#5815)
to be reverted.

Fixes moderneinc/customer-requests#1374
MBoegers added a commit that referenced this pull request Jan 29, 2026
…parent POMs

Convert `ChangeDependencyGroupIdAndArtifactId` from `Recipe` to
`ScanningRecipe` so that version properties defined in parent POMs
are updated when the dependency referencing that property is in a
child POM.

The scanner phase identifies version properties inherited from parent
POMs and records which source file defines each property. The visitor
phase then applies property updates when visiting those parent POM
files. All existing visitor logic is preserved unchanged, avoiding
the recipe-chaining issues that caused the previous attempt (#5815)
to be reverted.

Fixes moderneinc/customer-requests#1374
timtebeek added a commit that referenced this pull request Feb 17, 2026
…parent POMs (#6630)

* `ChangeDependencyGroupIdAndArtifactId` updates version properties in parent POMs

Convert `ChangeDependencyGroupIdAndArtifactId` from `Recipe` to
`ScanningRecipe` so that version properties defined in parent POMs
are updated when the dependency referencing that property is in a
child POM.

The scanner phase identifies version properties inherited from parent
POMs and records which source file defines each property. The visitor
phase then applies property updates when visiting those parent POM
files. All existing visitor logic is preserved unchanged, avoiding
the recipe-chaining issues that caused the previous attempt (#5815)
to be reverted.

Fixes moderneinc/customer-requests#1374

* Add test for shared property overlap scenario

Verifies that when a property in a parent POM is shared by multiple
dependencies in a child POM, and only one dependency matches the change
criteria, the property is left unchanged and the version is inlined instead.

* Check sibling modules for overlapping property usage

When a version property in a parent POM is shared by dependencies across
different child modules, changing it would break non-matching siblings.
The existing overlap filter only checked the current module's children
and parent dependencies, but not sibling modules.

Walk up the parent chain and check each parent's children to detect
property usage conflicts in sibling modules. When overlap is found,
the version is inlined instead of updating the shared property.

* Add test documenting conservative behavior for redefined child properties

When a child module redefines a parent property used by a non-matching
dependency, the overlap filter conservatively prevents updating the
parent property. This is safe because ChangePropertyValue via doAfterVisit
does not scope to a single document and would also change the child's
intentional override.

* Avoid traversal when newVersion or compartor is null

* Add an early return after handling property tag

---------

Co-authored-by: Tim te Beek <tim@moderne.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working dependencies maven

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants