-
Notifications
You must be signed in to change notification settings - Fork 503
Preserve implicitly defined version properties in Maven recipes #6691
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
rewrite-maven/src/test/java/org/openrewrite/maven/ChangeDependencyGroupIdAndArtifactIdTest.java
Outdated
Show resolved
Hide resolved
...e-maven/src/main/java/org/openrewrite/maven/ChangeManagedDependencyGroupIdAndArtifactId.java
Outdated
Show resolved
Hide resolved
rewrite-maven/src/main/java/org/openrewrite/maven/ChangeDependencyGroupIdAndArtifactId.java
Outdated
Show resolved
Hide resolved
...ven/src/test/java/org/openrewrite/maven/ChangeManagedDependencyGroupIdAndArtifactIdTest.java
Outdated
Show resolved
Hide resolved
rewrite-maven/src/test/java/org/openrewrite/maven/UpgradeDependencyVersionTest.java
Show resolved
Hide resolved
- 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
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.
timtebeek
approved these changes
Feb 10, 2026
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
DependencyVulnerabilityCheck,UpgradeDependencyVersion, andChangeDependencyGroupIdAndArtifactIdwould incorrectly replace implicitly defined version properties (like${project.parent.version},${project.version},${revision}) with hardcoded version valuesChanges
isImplicitlyDefinedVersionProperty()method toMavenVisitorto check if a value is an implicitly defined propertychangeChildTagValue()inMavenVisitorto skip changes when the old value is an implicitly defined version propertyChangeDependencyGroupIdAndArtifactIdandChangeManagedDependencyGroupIdAndArtifactIdwhere they directly useChangeTagValueVisitorTest plan
shouldPreserveProjectParentVersionPropertyInDependencyVersionthat verifies${project.parent.version}is preserved when upgrading dependency versionsshouldPreserveProjectVersionPropertyInDependencyVersionthat verifies${project.version}is preservedshouldPreserveRevisionPropertyInDependencyVersionthat verifies${revision}is preserved