[maven-4.0.x] Fix #12304: replace deprecated property expressions in mvnup - #12308
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates Maven’s mvnup compatibility fixer to rewrite deprecated prefixless Maven model expressions (${version}, ${groupId}, ${artifactId}) to their ${project.*} equivalents, and also adjusts DefaultSourceRoot to treat a normalized "." resource targetPath as absent.
Changes:
- Add recursive DOM traversal in
CompatibilityFixStrategyto replace deprecated shorthand expressions before undefined-property checks run. - Add unit tests covering the new deprecated-expression replacements in various POM locations.
- Normalize
DefaultSourceRootresourcetargetPathso"."becomes “absent” and"./subdir"becomes"subdir", with new unit tests.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| impl/maven-impl/src/main/java/org/apache/maven/impl/DefaultSourceRoot.java | Treats normalized empty targetPath (e.g., ".") as absent (null). |
| impl/maven-impl/src/test/java/org/apache/maven/impl/DefaultSourceRootTest.java | Adds tests for "." and "./subdir" targetPath normalization behavior. |
| impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/mvnup/goals/CompatibilityFixStrategy.java | Adds deprecated `${version |
| impl/maven-cli/src/test/java/org/apache/maven/cling/invoker/mvnup/goals/CompatibilityFixStrategyTest.java | Adds unit tests validating deprecated-expression replacements and a non-modification case. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+232
to
+258
| /** GH-12306: {@code targetPath="."} normalizes to an empty path and must be treated as absent. */ | ||
| @Test | ||
| void testHandlesDotTargetPathFromResource() { | ||
| Resource resource = Resource.newBuilder() | ||
| .directory("src/main/resources") | ||
| .targetPath(".") | ||
| .build(); | ||
|
|
||
| DefaultSourceRoot sourceRoot = new DefaultSourceRoot(Path.of("myproject"), ProjectScope.MAIN, resource); | ||
|
|
||
| assertFalse(sourceRoot.targetPath().isPresent(), "targetPath \".\" should be treated as absent"); | ||
| } | ||
|
|
||
| /** GH-12306: {@code targetPath="./subdir"} normalizes to {@code "subdir"} and must be preserved. */ | ||
| @Test | ||
| void testHandlesDotRelativeTargetPathFromResource() { | ||
| Resource resource = Resource.newBuilder() | ||
| .directory("src/main/resources") | ||
| .targetPath("./subdir") | ||
| .build(); | ||
|
|
||
| DefaultSourceRoot sourceRoot = new DefaultSourceRoot(Path.of("myproject"), ProjectScope.MAIN, resource); | ||
|
|
||
| assertTrue( | ||
| sourceRoot.targetPath().isPresent(), "targetPath \"./subdir\" should be present after normalization"); | ||
| assertEquals(Path.of("subdir"), sourceRoot.targetPath().orElseThrow()); | ||
| } |
Comment on lines
+763
to
+800
| /** | ||
| * Fixes deprecated Maven 2/3 shorthand property expressions throughout the POM. | ||
| * Replaces ${version}, ${groupId}, and ${artifactId} with their ${project.*} equivalents, | ||
| * which are the only forms supported in Maven 4. | ||
| */ | ||
| private boolean fixDeprecatedPropertyExpressions(Document pomDocument, UpgradeContext context) { | ||
| return fixDeprecatedPropertyExpressionsInElement(pomDocument.root(), context); | ||
| } | ||
|
|
||
| private boolean fixDeprecatedPropertyExpressionsInElement(Element element, UpgradeContext context) { | ||
| boolean fixed = false; | ||
|
|
||
| List<Element> children = element.childElements().toList(); | ||
|
|
||
| if (children.isEmpty()) { | ||
| String text = element.textContent(); | ||
| if (text != null && !text.isEmpty()) { | ||
| String fixedText = replaceDeprecatedExpressions(text); | ||
| if (!fixedText.equals(text)) { | ||
| element.textContent(fixedText); | ||
| context.detail("Fixed: replaced deprecated property expression in <" + element.name() + ">: " | ||
| + text.trim() + " → " + fixedText.trim()); | ||
| fixed = true; | ||
| } | ||
| } | ||
| } else { | ||
| for (Element child : children) { | ||
| fixed |= fixDeprecatedPropertyExpressionsInElement(child, context); | ||
| } | ||
| } | ||
|
|
||
| return fixed; | ||
| } | ||
|
|
||
| private static String replaceDeprecatedExpressions(String text) { | ||
| return text.replace("${version}", "${project.version}") | ||
| .replace("${groupId}", "${project.groupId}") | ||
| .replace("${artifactId}", "${project.artifactId}"); |
cstamas
approved these changes
Jun 18, 2026
… to mvnup
Maven 3 supported ${version}, ${groupId}, and ${artifactId} as shorthand
aliases for their ${project.*} equivalents. Maven 4 drops these deprecated
aliases (see #12304), causing builds to fail.
Add fixDeprecatedPropertyExpressions() to CompatibilityFixStrategy that
scans all text content in the POM and replaces the deprecated expressions
with their ${project.*} equivalents. This fix runs before the undefined
property expression check so that already-replaced expressions are not
falsely flagged.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
gnodet
force-pushed
the
fix-mvnup-deprecated-properties
branch
from
June 18, 2026 11:51
26fd4f5 to
945f296
Compare
gnodet
added a commit
that referenced
this pull request
Jun 18, 2026
… to mvnup (#12308) (#12313) Maven 3 supported ${version}, ${groupId}, and ${artifactId} as shorthand aliases for their ${project.*} equivalents. Maven 4 drops these deprecated aliases (see #12304), causing builds to fail. Add fixDeprecatedPropertyExpressions() to CompatibilityFixStrategy that scans all text content in the POM and replaces the deprecated expressions with their ${project.*} equivalents. This fix runs before the undefined property expression check so that already-replaced expressions are not falsely flagged. Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
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
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
Adds
fixDeprecatedPropertyExpressions()toCompatibilityFixStrategythat replaces deprecated Maven 2/3 shorthand properties (${version},${groupId},${artifactId}) with their Maven 4-compatible${project.*}equivalents.The
DefaultSourceRoottargetPath fix (#12306) has been split into a separate PR: #12311.Fixes #12304
Test plan
CompatibilityFixStrategyTest— 5 new tests inDeprecatedPropertyExpressionFixesTests🤖 Generated with Claude Code