[MNG-8708] Fix Maven 4 parent inference - #12703
Conversation
Distinguish explicitly declared parent coordinates from values inferred through relativePath. Infer an omitted parent version from the matching reactor model before raw-model validation. Signed-off-by: goutamadwant <workwithgoutam@gmail.com>
gnodet
left a comment
There was a problem hiding this comment.
Well-structured fix for MNG-8708. The inferParentVersion method correctly follows the same structural pattern as the existing inferDependencyVersion (reactor lookup, version fallback to parent's parent, location preservation), and the switch from value-based to location-based checking in the validator correctly distinguishes between user-declared and resolution-inferred coordinates.
The PR handles all three MNG-8708 scenarios: (1) path-only children no longer get false warnings, (2) explicit coordinates + relativePath still produce the warning, and (3) children specifying only groupId/artifactId can now infer the parent version from the reactor.
A few non-blocking observations:
-
Mixin validation consistency (line ~378 in
DefaultModelValidator): The analogous mixin validation still uses the old value-based pattern (mixin.getGroupId() != null && !mixin.getGroupId().isEmpty()). If mixin resolution follows the same inference path, it may need the same location-based treatment in a follow-up. -
Null safety in
inferParentVersion(line ~660 inDefaultModelBuilder): IfversionLocationis null (reactor parent has no explicit<version>and no parent), theBuilder.location()call silently does nothing. Safe in practice since a valid parent must have a version, but a defensive comment would improve clarity. -
Test coverage: The test covers the two main MNG-8708 scenarios but doesn't exercise the fallback path where the parent model's version is inherited from its own parent (lines 662-665). A three-level test (grandparent with version → versionless parent → child inferring) would strengthen coverage.
This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.
Claude Code on behalf of gnodet
Fixes #10377.
This fixes Maven 4.1.0 parent inference for reactor projects when parent coordinates are partially omitted.
The file-to-raw model transformation now:
Parent validation now checks whether
groupIdorartifactIdwas explicitly declared before warning about combining coordinates withrelativePath. Values inferred from a relative parent POM no longer trigger the warning.The existing warning remains in place when a POM explicitly declares both a non-empty
relativePathand parent coordinates.Following this checklist to help us incorporate your
contribution quickly and easily:
Note that commits might be squashed by a maintainer on merge.
This may not always be possible but is a best-practice.
mvn verifyto make sure basic checks pass.A more thorough check will be performed on your pull request automatically.
Tests
mvn verifyMavenITmng8708ParentInferenceTest: 2 tests passedMavenITmng8708ParentInferenceTest,MavenITmng8294ParentChecksTest: 8 tests passedmaven-impl: 550 tests passed, 4 skippedReporter reproduction: all three reactor projects build, and only the explicitly combined parent declaration emits the warning
mvn -Prun-its verify: source modules passed; the broad Core IT suite reported two unrelated DI fixture errors becauseorg.apache.maven:maven-testing:4.1.0-SNAPSHOTwas unavailableI hereby declare this contribution to be licenced under the Apache License Version 2.0, January 2004
In any other case, please file an Apache Individual Contributor License Agreement.