Skip to content

Fix BOM packaging in consumer POMs#11427

Merged
gnodet merged 1 commit intoapache:masterfrom
gnodet:fix-bom-consumer-pom
Nov 18, 2025
Merged

Fix BOM packaging in consumer POMs#11427
gnodet merged 1 commit intoapache:masterfrom
gnodet:fix-bom-consumer-pom

Conversation

@gnodet
Copy link
Contributor

@gnodet gnodet commented Nov 10, 2025

This PR addresses two issues with BOM (Bill of Materials) handling in consumer POMs reported in https://lists.apache.org/thread/41q40v598pd8mr32lmgwdfb2xm7lzm6l:

Issues Fixed

1. BOM packaging not transformed to POM in consumer POMs

When a project uses packaging=bom, the consumer POM was incorrectly retaining this packaging type. Since 'bom' is not a valid packaging type in Maven 4.0.0 model, this caused errors when the consumer POM was used.

2. Dependency versions preserved in dependencyManagement

When using -Dmaven.consumer.pom.flatten=true with a BOM, dependencies in dependencyManagement were missing their version tags.

Solution

The fix ensures that:

  • BOM packaging is always transformed to 'pom' in consumer POMs, regardless of whether flattening is enabled
  • Dependency versions are properly preserved in the consumer POM for both flattened and non-flattened BOMs

Changes

  • Modified DefaultConsumerPomBuilder.build() to detect BOMs based on original packaging and handle them appropriately
  • Added buildBomWithoutFlatten() method to handle BOMs when flattening is disabled, using the raw model but still transforming packaging
  • Added integration test to verify both issues are fixed

Testing

Manual testing confirms:

  • Consumer POMs for BOMs now have packaging=pom instead of packaging=bom
  • Dependency versions are preserved in dependencyManagement sections
  • Both with and without -Dmaven.consumer.pom.flatten=true work correctly

Pull Request opened by Augment Code with guidance from the PR author

gnodet added a commit to gnodet/maven that referenced this pull request Nov 10, 2025
…ting

Fixes apachegh-11427

This commit enhances the @MojoParameter annotation to support injection of
complex data types when unit testing mojos, with comprehensive test coverage.

Key features:

1. Added xml attribute to @MojoParameter annotation:
   - xml=true (default): Parse value as XML content (existing behavior)
   - xml=false: Treat value as plain text, escaping XML special characters
   - Enables comma-separated lists and values with special characters

2. Updated MojoExtension to handle the xml flag:
   - When xml=true, value is parsed as XML elements
   - When xml=false, value is escaped and treated as plain text
   - Properly handles special characters like <, >, &, etc.

3. Added comprehensive unit tests (15 new tests) covering:
   - List<String> with XML format
   - List<String> with comma-separated format using xml=false
   - String arrays with both XML and comma-separated formats
   - Map<String, String> with XML format
   - Properties with XML format
   - Custom bean objects with nested properties
   - Primitive types (int, boolean)
   - Special characters in values with xml=false

4. Fixed plugin.xml type declarations:
   - Changed from java.lang.List&lt;java.lang.String&gt; (HTML-encoded)
   - To java.util.List (proper Maven plugin descriptor format)
   - Maven's plugin descriptor doesn't support parameterized types in <type>
   - Added proper type declarations for Map, Properties, arrays, and custom beans

All tests pass successfully (22 tests in maven-testing module).
@gnodet gnodet added bug Something isn't working backport-to-4.0.x labels Nov 13, 2025
This commit addresses two issues with BOM (Bill of Materials) handling in consumer POMs:

1. BOM packaging not transformed to POM in consumer POMs:
   When a project uses packaging=bom, the consumer POM was incorrectly
   retaining this packaging type. Since 'bom' is not a valid packaging
   type in Maven 4.0.0 model, this caused errors when the consumer POM
   was used. The fix ensures that BOM packaging is always transformed
   to 'pom' in consumer POMs, regardless of whether flattening is enabled.

2. Dependency versions preserved in dependencyManagement:
   The effective model already contains resolved versions for dependencies
   in dependencyManagement sections. The fix ensures these versions are
   properly preserved in the consumer POM for both flattened and
   non-flattened BOMs.

Changes:
- Modified DefaultConsumerPomBuilder.build() to detect BOMs based on
  original packaging and handle them appropriately
- Added buildBomWithoutFlatten() method to handle BOMs when flattening
  is disabled, using the raw model but still transforming packaging
- Added integration test to verify both issues are fixed

Fixes issues reported in:
https://lists.apache.org/thread/41q40v598pd8mr32lmgwdfb2xm7lzm6l
@gnodet gnodet force-pushed the fix-bom-consumer-pom branch from 0f318a7 to 3465bf1 Compare November 14, 2025 07:58
@gnodet gnodet requested a review from cstamas November 14, 2025 08:03
@gnodet gnodet merged commit 7d6fd87 into apache:master Nov 18, 2025
22 checks passed
@github-actions github-actions bot added this to the 4.1.0 milestone Nov 18, 2025
@gnodet
Copy link
Contributor Author

gnodet commented Nov 18, 2025

💚 All backports created successfully

Status Branch Result
maven-4.0.x

Questions ?

Please refer to the Backport tool documentation

gnodet added a commit to gnodet/maven that referenced this pull request Nov 18, 2025
This commit addresses two issues with BOM (Bill of Materials) handling in consumer POMs:

1. BOM packaging not transformed to POM in consumer POMs:
   When a project uses packaging=bom, the consumer POM was incorrectly
   retaining this packaging type. Since 'bom' is not a valid packaging
   type in Maven 4.0.0 model, this caused errors when the consumer POM
   was used. The fix ensures that BOM packaging is always transformed
   to 'pom' in consumer POMs, regardless of whether flattening is enabled.

2. Dependency versions preserved in dependencyManagement:
   The effective model already contains resolved versions for dependencies
   in dependencyManagement sections. The fix ensures these versions are
   properly preserved in the consumer POM for both flattened and
   non-flattened BOMs.

Changes:
- Modified DefaultConsumerPomBuilder.build() to detect BOMs based on
  original packaging and handle them appropriately
- Added buildBomWithoutFlatten() method to handle BOMs when flattening
  is disabled, using the raw model but still transforming packaging
- Added integration test to verify both issues are fixed

Fixes issues reported in:
https://lists.apache.org/thread/41q40v598pd8mr32lmgwdfb2xm7lzm6l

(cherry picked from commit 7d6fd87)
gnodet added a commit that referenced this pull request Nov 18, 2025
This commit addresses two issues with BOM (Bill of Materials) handling in consumer POMs:

1. BOM packaging not transformed to POM in consumer POMs:
   When a project uses packaging=bom, the consumer POM was incorrectly
   retaining this packaging type. Since 'bom' is not a valid packaging
   type in Maven 4.0.0 model, this caused errors when the consumer POM
   was used. The fix ensures that BOM packaging is always transformed
   to 'pom' in consumer POMs, regardless of whether flattening is enabled.

2. Dependency versions preserved in dependencyManagement:
   The effective model already contains resolved versions for dependencies
   in dependencyManagement sections. The fix ensures these versions are
   properly preserved in the consumer POM for both flattened and
   non-flattened BOMs.

Changes:
- Modified DefaultConsumerPomBuilder.build() to detect BOMs based on
  original packaging and handle them appropriately
- Added buildBomWithoutFlatten() method to handle BOMs when flattening
  is disabled, using the raw model but still transforming packaging
- Added integration test to verify both issues are fixed

Fixes issues reported in:
https://lists.apache.org/thread/41q40v598pd8mr32lmgwdfb2xm7lzm6l

(cherry picked from commit 7d6fd87)
gnodet added a commit that referenced this pull request Nov 26, 2025
…ting (#11426)

Fixes gh-11427

This commit enhances the @MojoParameter annotation to support injection of
complex data types when unit testing mojos, with comprehensive test coverage.

Key features:

1. Added xml attribute to @MojoParameter annotation:
   - xml=true (default): Parse value as XML content (existing behavior)
   - xml=false: Treat value as plain text, escaping XML special characters
   - Enables comma-separated lists and values with special characters

2. Updated MojoExtension to handle the xml flag:
   - When xml=true, value is parsed as XML elements
   - When xml=false, value is escaped and treated as plain text
   - Properly handles special characters like <, >, &, etc.

3. Added comprehensive unit tests (15 new tests) covering:
   - List<String> with XML format
   - List<String> with comma-separated format using xml=false
   - String arrays with both XML and comma-separated formats
   - Map<String, String> with XML format
   - Properties with XML format
   - Custom bean objects with nested properties
   - Primitive types (int, boolean)
   - Special characters in values with xml=false

4. Fixed plugin.xml type declarations:
   - Changed from java.lang.List&lt;java.lang.String&gt; (HTML-encoded)
   - To java.util.List (proper Maven plugin descriptor format)
   - Maven's plugin descriptor doesn't support parameterized types in <type>
   - Added proper type declarations for Map, Properties, arrays, and custom beans
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.

2 participants