Skip to content

MNG-8667: Recognize injected parent profiles during validation - #13205

Merged
gnodet merged 1 commit into
apache:masterfrom
goutamadwant:fix-mng-8667-parent-profiles
Sep 22, 2026
Merged

gnodet merged 1 commit into
apache:masterfrom
goutamadwant:fix-mng-8667-parent-profiles

Conversation

@goutamadwant

Copy link
Copy Markdown
Contributor

Fixes #10427.

Problem

Maven 4 can successfully build a project's effective model while failing to construct a separate MavenProject for its parent. The active parent profiles still contribute to the effective model and are recorded in MavenProject#getInjectedProfileIds(), but DefaultMaven#getAllProfiles() only searches profiles reachable through MavenProject#getParent().

As a result, Maven incorrectly reports active parent profiles as nonexistent when building against an empty local repository.

The failure was reproduced against jenkinsci/text-finder-plugin using Maven 4.1.0-SNAPSHOT and a new empty local repository:

mvn -B -ntp -Dmaven.repo.local=/path/to/empty-repository validate

Before this change, Maven stopped with:

The requested profiles [might-produce-incrementals, consume-incrementals] could not be activated or deactivated because they do not exist.

Change

Include profile IDs already recorded in MavenProject#getInjectedProfileIds() when collecting the profiles available for requested-profile validation.

These IDs represent profiles that have already contributed to the effective model. This handles the unavailable-parent-project path without accepting arbitrary missing profile names.

A focused regression test covers a project whose effective model contains an injected parent profile while its parent MavenProject is unavailable.

Validation

  • The new regression test failed before the production change and passes afterward.
  • The patched Maven distribution successfully validates jenkinsci/text-finder-plugin using a new empty local repository.
  • MavenITmng7051OptionalProfileActivationTest passes all five tests, including the case confirming that an actually nonexistent required profile still fails the build.
  • The focused Core IT reactor verification completed successfully across 88 modules.
  • Checkstyle, Spotless, Apache RAT, and git diff --check passed.
  • The commit has a verified signature.

Checklist

  • This pull request addresses one issue without unrelated changes.
  • The description explains what the pull request changes, how, and why.
  • The commit has a meaningful subject line and body.
  • A unit test covers the behavioral change and fails without the runtime fix.
  • mvn verify completed successfully.
  • The relevant Core IT completed successfully.
  • I hereby declare this contribution to be licenced under the Apache License Version 2.0, January 2004.
  • In any other case, I have filed an Apache Individual Contributor License Agreement.

Profile validation normally discovers parent profiles by walking MavenProject parent links. When construction of a parent MavenProject fails, its active profiles can still contribute to the effective model but are omitted from validation. Include the recorded injected profile IDs when validating requested profiles and add a focused regression test for the unavailable-parent path.

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The fix is correct and well-targeted.

getAllProfiles() was missing one source: profile IDs already injected into the effective model (via MavenProject#getInjectedProfileIds()). These represent profiles that successfully contributed during model building — so treating them as "nonexistent" was always wrong. The fix adds the missing stream, and since the result is collected into a Set, any overlap with the existing settingsProfiles stream is harmlessly deduplicated.

The visibility change (private → package-private) is the standard Java white-box testing pattern used throughout this package — the test lives in package org.apache.maven, not in a different package or module. No public API is exposed.

The unit test directly asserts the regression: a project whose effective model contains an injected parent profile returns that profile ID from getAllProfiles() even when the parent MavenProject is unavailable. The assertion is specific (exact Set equality), and the complementary coverage (nonexistent required profiles still fail) is confirmed by the existing MavenITmng7051OptionalProfileActivationTest.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

@gnodet gnodet added bug Something isn't working backport-to-4.0.x labels Sep 21, 2026
@gnodet gnodet modified the milestones: 4.0.0, 4.1.0 Sep 21, 2026
@gnodet
gnodet merged commit 5cd1b60 into apache:master Sep 22, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-to-4.0.x bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[MNG-8667] Failed to build project against clean $HOME/.m2 (regression in Maven 4)

3 participants