Skip to content

Conversation

@Jenson3210
Copy link
Contributor

Summary

  • Fixes an issue where recipes like DependencyVulnerabilityCheck, UpgradeDependencyVersion, and ChangeDependencyGroupIdAndArtifactId would incorrectly replace implicitly defined version properties (like ${project.parent.version}, ${project.version}, ${revision}) with hardcoded version values
  • These properties represent intentional links to parent/project versions that should be preserved to maintain the relationship between child and parent module versions in multimodule Maven projects

Changes

  1. Added isImplicitlyDefinedVersionProperty() method to MavenVisitor to check if a value is an implicitly defined property
  2. Updated changeChildTagValue() in MavenVisitor to skip changes when the old value is an implicitly defined version property
  3. Added checks in ChangeDependencyGroupIdAndArtifactId and ChangeManagedDependencyGroupIdAndArtifactId where they directly use ChangeTagValueVisitor

Test plan

  • Added test shouldPreserveProjectParentVersionPropertyInDependencyVersion that verifies ${project.parent.version} is preserved when upgrading dependency versions
  • Added test shouldPreserveProjectVersionPropertyInDependencyVersion that verifies ${project.version} is preserved
  • Added test shouldPreserveRevisionPropertyInDependencyVersion that verifies ${revision} is preserved
  • All existing Maven tests pass

When upgrading dependency versions or changing dependency coordinates,
recipes like UpgradeDependencyVersion and ChangeDependencyGroupIdAndArtifactId
were incorrectly replacing implicitly defined version properties such as
${project.parent.version}, ${project.version}, and ${revision} with hardcoded
version values.

These properties represent intentional links to parent/project versions
that should be preserved to maintain the relationship between child and
parent module versions in multimodule Maven projects.

This fix adds explicit checks in MavenVisitor.changeChildTagValue() and
the direct ChangeTagValueVisitor calls in ChangeDependencyGroupIdAndArtifactId
and ChangeManagedDependencyGroupIdAndArtifactId to skip changes when the
current value is an implicitly defined version property.

Fixes: DependencyVulnerabilityCheck resolves parent version properties
to hardcoded values in multimodule Maven projects.
…ependencyGroupIdAndArtifactId

Add tests that verify implicitly defined version properties like
${project.parent.version} and ${project.version} are preserved when
using these recipes with a newVersion parameter.

These tests pass with the fix and fail without it, confirming the
fix was necessary for both recipes.
- Use isImplicitlyDefinedVersionProperty() in isProperty() for consistency
- Refactor empty if blocks to use negation instead of empty comment blocks
- Add clarifying comments to tests explaining the scenario uses related
  artifacts that share version numbering
@timtebeek timtebeek added bug Something isn't working recipe Requested Recipe maven labels Feb 9, 2026
timtebeek and others added 6 commits February 9, 2026 23:34
When newVersion is specified but the current version uses an implicitly
defined property like ${project.parent.version}, ${project.version}, or
${revision}, skip the entire change (including groupId/artifactId) to avoid
partial updates that would leave inconsistent state.
@github-project-automation github-project-automation bot moved this from In Progress to Ready to Review in OpenRewrite Feb 10, 2026
@timtebeek timtebeek merged commit 1eea4c8 into main Feb 10, 2026
1 check passed
@timtebeek timtebeek deleted the maven-property-resolution branch February 10, 2026 12:19
@github-project-automation github-project-automation bot moved this from Ready to Review to Done in OpenRewrite Feb 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working maven recipe Requested Recipe

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants