Hiteshsai007 opened a new pull request, #12745:
URL: https://github.com/apache/maven/pull/12745

   
   Resolves #10535 (MNG-8287)
   
   I have submitted a fix for this in PR #12744.
   
   Maven 4 introduces support for activating profiles based on the project's 
`<packaging>`. However, when a consumer POM generated by Maven 4 is consumed by 
tools such as Maven 3, Gradle, or IDEs that do not understand the 4.1.0+ 
`<packaging>` activation condition, dependency resolution can differ between 
tools.
   
   This change updates the consumer POM generation process in 
`DefaultConsumerPomBuilder` to resolve packaging-based profile activation when 
generating the consumer POM.
   
   ### How this solves the problem
   
   1. **Inline matching profiles**
   
      If a profile is activated by `<packaging>` and the packaging matches the 
project's packaging, the profile's contents are eagerly merged into the main 
model of the consumer POM, including:
   
      - dependencies
      - `dependencyManagement`
      - repositories
   
   2. **Remove resolved activation**
   
      After inlining a matching profile:
      
      - If `<packaging>` is the only activation condition, the profile is 
completely removed from the consumer POM.
      - If the profile has additional activation conditions (for example, 
`<jdk>` alongside `<packaging>`), the profile is preserved with its other 
conditions intact, while the already-resolved `<packaging>` condition is 
removed.
   
   3. **Preserve non-matching profiles**
   
      If a profile is activated by a packaging type that does not match the 
project's packaging, the profile is left unchanged in the consumer POM.
   
   ### Why this matters
   
   The `<packaging>` activation condition is supported by Maven 4, but older 
Maven versions and other build tools may not understand the 4.1.0+ model 
element.
   
   By resolving matching packaging-based profiles during consumer POM 
generation, downstream consumers receive the effective dependency information 
without needing to understand or resolve Maven 4's packaging-based activation 
themselves.
   
   This provides consistent dependency resolution across Maven versions and 
other consuming tools while preserving profiles that are not applicable to the 
current packaging.
   
   ### Testing
   
   Added unit test coverage in `ConsumerPomBuilderTest` for:
   
   - Matching packaging profiles being inlined into the consumer POM.
   - Profiles with only a `<packaging>` activation being removed after 
resolution.
   - Profiles with mixed activation conditions retaining their other conditions 
while removing `<packaging>`.
   - Non-matching packaging profiles remaining unchanged.
   
   Following this checklist to help us incorporate your
   contribution quickly and easily:
   
   - [x] Your pull request should address just one issue, without pulling in 
other changes.
   - [x] Write a pull request description that is detailed enough to understand 
what the pull request does, how, and why.
   - [x] Each commit in the pull request should have a meaningful subject line 
and body.
     Note that commits might be squashed by a maintainer on merge.
   - [x] Write unit tests that match behavioral changes, where the tests fail 
if the changes to the runtime are not applied.
     This may not always be possible but is a best-practice.
   - [x] Run `mvn verify` to make sure basic checks pass.
   - [x] You have run the [Core IT][core-its] successfully.
   
   If your pull request is about ~20 lines of code you don't need to sign an
   [Individual Contributor License 
Agreement](https://www.apache.org/licenses/icla.pdf) if you are unsure
   please ask on the developers list.
   
   To make clear that you license your contribution under
   the [Apache License Version 2.0, January 
2004](http://www.apache.org/licenses/LICENSE-2.0)
   you have to acknowledge this by using the following check-box.
   
   - [x] I hereby declare this contribution to be licenced under the [Apache 
License Version 2.0, January 2004](http://www.apache.org/licenses/LICENSE-2.0)
   - [ ] In any other case, please file an [Apache Individual Contributor 
License Agreement](https://www.apache.org/licenses/icla.pdf).
   
   [core-its]: https://maven.apache.org/core-its/core-it-suite/
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to