Repository navigation
Bugfix: use GAV and not GAPV in source labels for profiles - #12406
Conversation
This introduces no behaviour change between Maven 3 and 4, merely the labels for "source" of profiles got different. Fixes apache#12405
gnodet
left a comment
There was a problem hiding this comment.
Review: Bugfix — use GAV and not GAPV in source labels for profiles
Scope: 1 file changed (DefaultProjectBuilder.java), +11 / −1
Note: This review covers project conventions and code correctness. It does not replace specialized tools such as CodeRabbit, Sourcery, or SonarCloud.
Summary
The PR fixes a Maven 3 → 4 behavioral discrepancy in how profile source labels are identified in MavenProject.setInjectedProfileIds(). Maven 3's ModelData#getId() returned GAV (groupId:artifactId:version), but Maven 4's Model#getId() returns GAPV (groupId:artifactId:packaging:version). This subtle difference causes issues identifying reactor projects, as the packaging component is irrelevant for that purpose.
The fix replaces result.getEffectiveModel().getId() in the fallback path with a new getModelDataId() helper that emulates Maven 3's GAV format.
✅ No blocking issues found
The change is correct, well-scoped, and well-documented:
- Correctness: The new
getModelDataId()correctly emulates Maven 3'sModelData#getId()— producinggroupId:artifactId:versionwith[inherited]placeholders for null values - Scope: Minimal and focused — single logical change in the fallback path
- Issue linkage: Properly linked to #12405
- Tests: Existing test
testActivatedProfileBySourceinDefaultMavenProjectBuilderTestalready asserts GAV format for profile source keys - Documentation: Clear Javadoc on the new method explaining what it emulates
Observations (non-blocking)
-
Potential reuse of
ModelProblemUtils.toId(model)— TheDefaultModelBuilderalready hasModelProblemUtils.toId(model)which produces the same GAV format and is used for setting theprofilesByModelmap keys (lines 1490, 1961). The newgetModelDataId()does similar work but with different null-handling ([inherited]vs resolving from parent →[unknown-*]). SinceModelProblemUtilsis package-private inorg.apache.maven.impl.modeland the consumer is inorg.apache.maven.project, direct reuse isn't possible — so the separate method is justified. For the effective model (fully resolved), both methods produce identical output. -
Potentially related pre-existing inconsistency (out of scope) — In
DefaultModelBuilder.javaat line 1944, there isaddActivePomProfiles(cached.model().getId(), cached.activatedProfiles())which usesModel#getId()(GAPV), while lines 1490 and 1961 correctly useModelProblemUtils.toId()(GAV) for the same map. This could cause cache-hit entries to be stored under GAPV keys while everything else uses GAV keys. This might be worth investigating as a follow-up.
This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.
|
This should be backported to 4.0.x. |
Follow-up: same GAPV vs GAV inconsistency in
|
| Path | Line | Key format | Code |
|---|---|---|---|
| Cache miss | 1961 | GAV ✅ | ModelProblemUtils.toId(model) → g:a:v |
| Cache hit | 1944 | GAPV ❌ | cached.model().getId() → g:a:p:v |
The cache-miss path was already fixed (the comment on line 1960 even says "Use ModelProblemUtils.toId() to get groupId:artifactId:version format (without packaging)"), but the cache-hit path on line 1944 was missed — it still calls Model.getId() which includes packaging.
Practical impact
When multiple child projects share the same parent:
- Child A resolves parent P first → cache miss → P's profiles stored under GAV key (
org.example:parent:1.0) - Child B resolves parent P second → cache hit → P's profiles stored under GAPV key (
org.example:parent:pom:1.0)
So in DefaultProjectBuilder at line 807, when it iterates profilesByModel and calls setInjectedProfileIds(entry.getKey(), ...), the source label for the same parent's profiles would be different depending on whether the child happened to be first or second to resolve it. Non-deterministic — same bug class as this PR.
Suggested fix
One-liner on line 1944 of DefaultModelBuilder.java:
// Before (GAPV):
addActivePomProfiles(cached.model().getId(), cached.activatedProfiles());
// After (GAV):
addActivePomProfiles(ModelProblemUtils.toId(cached.model()), cached.activatedProfiles());ModelProblemUtils is already imported and used in the same file.
…urce keys The cache-hit path in readAsParentModel() used Model.getId() which returns groupId:artifactId:packaging:version (GAPV), while the cache-miss path correctly used ModelProblemUtils.toId() which returns groupId:artifactId:version (GAV). This inconsistency could cause the same parent's profiles to be stored under different keys depending on whether the parent model was resolved from cache or freshly built. Follow-up to apache#12406. Co-Authored-By: Claude Opus 4.6 <[email protected]>
This introduces no behaviour change between Maven 3 and 4, merely the labels for "source" of profiles got different.
Fixes #12405