[MNG-8287] Backport consumer POM packaging profile resolution to 4.0.x - #12967
Conversation
When generating a consumer POM, profiles activated by packaging that match the current project's packaging should have their content inlined into the consumer POM and the activation should be removed. This ensures consistent dependency resolution across different tools.
- Inline packaging-activated profiles during transformPom for non-flattened builds - Drop profiles activated by non-matching packaging entirely - Update ConsumerPomBuilderTest to enable flattening and assert on dropped profiles Signed-off-by: Hitesh <[email protected]>
- Add key-based deduplication when merging inlined dependencies, managed dependencies, and repositories from packaging-activated profiles to prevent duplicates in the consumer POM - Add unit tests for dependency management and repository inlining paths in inlinePackagingActivatedProfiles - Add unit test for duplicate dependency guard (model deps take precedence over profile duplicates) - Widen transformBom visibility to package-private to match transformNonPom and transformPom Signed-off-by: Hitesh <[email protected]>
The 'bom' packaging type is not supported by the model builder on the 4.0.x branch, so the testBomPackagingActivatedProfilesArePreserved test is rewritten as a pure unit test that constructs the Model directly instead of loading it from a file. Co-Authored-By: Claude Opus 4.6 <[email protected]>
gnodet
left a comment
There was a problem hiding this comment.
✅ Looks Good
Clean backport of PR #12744 (MNG-8287) from master to maven-4.0.x. The consumer POM packaging profile inlining logic is correct, all activation model fields are accounted for, and the test adaptations for 4.0.x are appropriate.
Technical notes:
- The core inlining logic in
inlinePackagingActivatedProfilescorrectly handles all four profile scenarios: matching-only-packaging (inline and remove), matching-with-other-conditions (strip packaging, keep profile), non-matching (drop entirely), and no-packaging-activation (keep as-is). The deduplication strategy usingputIfAbsentcorrectly gives model-level dependencies precedence over profile-declared duplicates. - The
stripPackagingActivationmethod covers all sevenActivationmodel fields (activeByDefault, jdk, os, property, file, packaging, condition). The packaging field is correctly omitted from the emptiness check since it was already stripped to null. - The BOM test adaptation to a pure unit test is a pragmatic choice since
bompackaging is not supported by the model builder on 4.0.x. The test still validates thattransformBompreserves packaging-activated profiles for child modules. - On master,
stripPackagingActivationdelegates to a sharedisActivationEmpty()method. The backport correctly inlines this check sinceisActivationEmptydoes not exist on 4.0.x. The two implementations are logically equivalent.
Minor observation:
ConsumerPomBuilderTest.java(lines ~432, 480-481): unnecessary escape of single quotes in double-quoted Java strings (\'1.0.0\'→'1.0.0'). Compiles correctly but appears to be a merge conflict resolution artifact.
📋 PR Metadata
| Aspect | Current | Suggested |
|---|---|---|
| Labels | (none) | bug |
🔀 Backport Status
- ⏳
master— #12744 (OPEN, original) - ✅
maven-4.0.x— this PR - ℹ️ Maven 3.x — not needed (packaging-based profile activation is a 4.x feature)
🤖 This review was generated by ForgeBot.
When inlining packaging-activated profiles, import-scoped entries in dependencyManagement (BOM imports) were not filtered out. These entries are flattened during resolution and must not reappear in the consumer POM. Co-Authored-By: Claude Opus 4.6 <[email protected]>
gnodet
left a comment
There was a problem hiding this comment.
✅ Delta Review — New Commit Looks Good
New commit cb86a141 is a clean, focused fix that filters import-scoped managed dependencies (BOM imports) from inlined packaging-activated profiles before they leak into the consumer POM. Faithful backport of the equivalent upstream commit bf21878 on #12744.
Technical notes on the new commit:
- Correctly identifies that import-scoped entries in
dependencyManagementare BOM-import directives that get flattened during resolution. Re-emitting them in the consumer POM would cause downstream consumers to redundantly re-import those BOMs. - The
"import".equals(dep.getScope())pattern is null-safe (callingequalson the literal). - The new test
testImportScopedManagedDepsAreFilteredFromInlinedProfilesis thorough: sets up both an import-scoped BOM entry and a regular managed dependency, verifies the profile is inlined (removed), and asserts only the regular dependency survives.
Minor observation (cosmetic): After removeIf filters import-scoped entries, the additionalManagedDeps list could become empty (if all managed deps were import-scoped). In that scenario an empty <dependencyManagement/> element could be introduced. Extremely unlikely in practice.
Previous finding (unnecessary quote escaping in test strings) still applies.
🤖 This review was generated by ForgeBot.
Resolve conflicts in DefaultConsumerPomBuilder.java and ConsumerPomBuilderTest.java: keep both packaging profile inlining and executable condition stripping, with stripPackagingActivation delegating to the shared isActivationEmpty method. Co-Authored-By: Claude Opus 4.6 <[email protected]>
These files were inadvertently included during the merge and cause the RAT license check to fail. Co-Authored-By: Claude Opus 4.6 <[email protected]>
|
@gnodet Please assign appropriate label to PR according to the type of change. |
Summary
Backport of #12744 to the
maven-4.0.xbranch.testBomPackagingActivatedProfilesArePreservedto a pure unit test sincebompackaging is not supported by the model builder on 4.0.xChanges
Maven 4 introduces support for activating profiles based on the project's
<packaging>type. However, when a dependency built with Maven 4 is consumed by tools such as Maven 3, Gradle, or IDEs that do not understand the<packaging>activation condition, dependency resolution can differ between tools.This change updates consumer POM generation to resolve packaging-based profile activation before the consumer POM is published, ensuring that downstream consumers see a consistent and predictable set of dependencies.
Test plan
ConsumerPomBuilderTesttests pass on 4.0.x🤖 Generated with Claude Code