Skip to content

[MNG-8708] Fix Maven 4 parent inference - #12703

Open
goutamadwant wants to merge 1 commit into
apache:masterfrom
goutamadwant:fix-parent-relative-path-resolution
Open

[MNG-8708] Fix Maven 4 parent inference#12703
goutamadwant wants to merge 1 commit into
apache:masterfrom
goutamadwant:fix-parent-relative-path-resolution

Conversation

@goutamadwant

Copy link
Copy Markdown

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:

  • infers a missing parent version from the matching reactor model before raw-model validation;
  • preserves the inferred version's source location.

Parent validation now checks whether groupId or artifactId was explicitly declared before warning about combining coordinates with relativePath. 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 relativePath and parent coordinates.

Following this checklist to help us incorporate your
contribution quickly and easily:

  • Your pull request should address just one issue, without pulling in other changes.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Each commit in the pull request should have a meaningful subject line and body.
    Note that commits might be squashed by a maintainer on merge.
  • Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied.
    This may not always be possible but is a best-practice.
  • Run mvn verify to make sure basic checks pass.
    A more thorough check will be performed on your pull request automatically.
  • You have run the Core IT successfully.

Tests

  • mvn verify

  • MavenITmng8708ParentInferenceTest: 2 tests passed

  • MavenITmng8708ParentInferenceTest,MavenITmng8294ParentChecksTest: 8 tests passed

  • maven-impl: 550 tests passed, 4 skipped

  • Reporter 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 because org.apache.maven:maven-testing:4.1.0-SNAPSHOT was unavailable

  • I 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.

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 gnodet left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 in DefaultModelBuilder): If versionLocation is null (reactor parent has no explicit <version> and no parent), the Builder.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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[MNG-8708] Maven 4 inaccurate error and warning with parent relative path of ../..

2 participants