MNG-8667: Recognize injected parent profiles during validation - #13205
Conversation
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
left a comment
There was a problem hiding this comment.
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.
Fixes #10427.
Problem
Maven 4 can successfully build a project's effective model while failing to construct a separate
MavenProjectfor its parent. The active parent profiles still contribute to the effective model and are recorded inMavenProject#getInjectedProfileIds(), butDefaultMaven#getAllProfiles()only searches profiles reachable throughMavenProject#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-pluginusing Maven 4.1.0-SNAPSHOT and a new empty local repository:mvn -B -ntp -Dmaven.repo.local=/path/to/empty-repository validateBefore 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
MavenProjectis unavailable.Validation
jenkinsci/text-finder-pluginusing a new empty local repository.MavenITmng7051OptionalProfileActivationTestpasses all five tests, including the case confirming that an actually nonexistent required profile still fails the build.git diff --checkpassed.Checklist
mvn verifycompleted successfully.