Skip to content

[GH-11772] Fail-fast consumer POM validation for non-4.0.0 model versions#11780

Open
gnodet wants to merge 1 commit intomasterfrom
gh-11772-consumer-pom-validation
Open

[GH-11772] Fail-fast consumer POM validation for non-4.0.0 model versions#11780
gnodet wants to merge 1 commit intomasterfrom
gh-11772-consumer-pom-validation

Conversation

@gnodet
Copy link
Contributor

@gnodet gnodet commented Mar 10, 2026

Summary

Fixes #11772

When a POM-packaged project (parent POM) uses Maven 4.1.0 features like profile conditions that cannot be stripped during consumer POM transformation, the build now fails fast with actionable guidance instead of silently deploying a consumer POM that Maven 3 and Gradle cannot resolve.

Changes

  • Consumer POM validation (DefaultConsumerPomBuilder): After building the consumer POM for a POM-packaged project on the non-flatten path, validates that the computed model version is 4.0.0. If not, throws a MavenException listing the available options:

    1. Enable flattening (maven.consumer.pom.flatten=true)
    2. Preserve the model version (preserve.model.version=true)
    3. Remove the incompatible features
  • Managed dependency removal flag (Constants / Features): Added maven.consumer.pom.removeUnusedManagedDependencies property (default: true) to control whether unused managed dependencies are removed during consumer POM flattening.

Scope

The validation only applies to:

  • POM-packaged projects (parent POMs) — non-POM projects (jar, war, etc.) are consumed as dependencies where Maven 3 ignores unknown elements, so a higher model version is acceptable (only a warning is logged)
  • The non-flatten path — when flattening is enabled, the transformation handles what it can (e.g. mixins are intentionally kept for POM-packaged projects with model version 4.2.0)
  • Projects without preserve.model.version=true

Use cases

Scenario Outcome
4.1.0 parent with root/subprojects only (e.g. JLine) Consumer POM is naturally 4.0.0 after transformation — no intervention needed
4.1.0 parent with profile conditions Build fails with actionable error message
4.2.0 POM with mixins + flatten Existing behavior preserved — mixins kept, model version 4.2.0
4.2.0 POM with mixins, no flatten Existing mixin-specific error preserved

Test plan

  • Unit test: testParentWithConditionsFailsConsumerPom — validates fail-fast for profile conditions
  • Unit test: testMultiModuleConsumerPreserveModelVersion — validates preserveModelVersion bypass
  • IT: MavenITgh11772ConsumerPom410Test — verifies consumer POMs are 4.0.0 and build POMs retain 4.1.0 content for a parent+child project using 4.1.0 namespace

@gnodet gnodet changed the title [GH-11772] Add managed dep removal flag and consumer POM validation [GH-11772] Consumer POM validation and build POM parent resolution Mar 10, 2026
@gnodet gnodet changed the title [GH-11772] Consumer POM validation and build POM parent resolution [GH-11772] Fail-fast consumer POM validation for non-4.0.0 model versions Mar 10, 2026
…ions

When a POM-packaged project (parent POM) uses Maven 4.1.0 features
like profile conditions that cannot be stripped during consumer POM
transformation, the build now fails fast with actionable guidance
instead of silently deploying a consumer POM that Maven 3 and Gradle
cannot resolve.

The validation applies only to:
- POM-packaged projects (parent POMs) on the non-flatten path
- Projects without preserve.model.version=true

Also adds a maven.consumer.pom.removeUnusedManagedDependencies property
(default: true) to control whether unused managed dependencies are
removed during consumer POM flattening.
@gnodet gnodet force-pushed the gh-11772-consumer-pom-validation branch from de91c68 to 8b30eac Compare March 10, 2026 21:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Consumer POM of parent POMs currently remain at modelVersion 4.1.0, breaking Maven 3 and Gradle consumers

3 participants