Skip to content

[Backport maven-3.10.x] Fix #13479: Accept the ? optional-profile prefix in -P - #13549

Closed
charangowdamd-cmd wants to merge 1 commit into
apache:maven-3.10.xfrom
charangowdamd-cmd:fix/13479-optional-profile-prefix
Closed

charangowdamd-cmd wants to merge 1 commit into
apache:maven-3.10.xfrom
charangowdamd-cmd:fix/13479-optional-profile-prefix

Conversation

@charangowdamd-cmd

@charangowdamd-cmd charangowdamd-cmd commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #13479.

Description

Maven 4 treats -P ?id as an optional profile (MNG-7051): activate it if it exists, skip it otherwise. In Maven 3.x, -P ?id was read literally as a profile named ?id, which caused a warning that ?id does not exist and left the real profile unactivated. This causes builds that pass -P ?profile (such as CI matrices testing Maven 3 and 4 side by side) to silently skip profiles on Maven 3.

This PR adds support for accepting ? after +, -, and ! prefixes in -P, aligning with Maven 4's prefix evaluation order, and skipping any degenerate tokens that are left empty after stripping prefixes.

Changes

  • Extracted profile activation option handling into package-private performProfileActivation(CommandLine, List, List) in MavenCli.
  • Stripped leading ? optional-profile marker after processing +, -, or ! prefixes.
  • Skipped tokens that become empty after stripping prefixes.
  • Added unit tests estOptionalProfiles and estDegenerateProfileTokens in MavenCliTest.

Following this checklist to help us incorporate your contribution quickly and easily:

  • Your pull request should address just one issue, without pulling in other changes.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • 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.
  • 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.
  • Run mvn verify to make sure basic checks pass.
    A more thorough check will be performed on your pull request automatically.
  • You have run the Core IT successfully.

If your pull request is about ~20 lines of code you don't need to sign an
Individual Contributor License Agreement 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
you have to acknowledge this by using the following check-box.

Maven 4 reads -P ?id as an optional profile (MNG-7051); Maven 3 read it as a profile named ?id and left id off. The prefix is now removed after the +, - and ! prefixes, in the same order as Maven 4. Empty tokens left after stripping prefixes are skipped.
@github-actions

This comment has been minimized.

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean, correct backport of Maven 4's optional-profile ? prefix handling to 3.10.x. The prefix-stripping order (sign prefix → ? → empty check) matches Maven 4's performProfileActivation, and the tests correctly validate the new behavior — testOptionalProfiles() would fail without the fix since the old code would leave ?run-its with the ? prefix in the active list. Edge cases (bare ?, !?, +?, consecutive commas) are covered by testDegenerateProfileTokens().

This review was generated by an AI agent, Hermès on behalf of @gnodet.

@gnodet gnodet changed the title Fix #13479: Accept the ? optional-profile prefix in -P [Backport maven-3.10.x] Fix #13479: Accept the ? optional-profile prefix in -P Oct 19, 2026
@slawekjaranowski

Copy link
Copy Markdown
Member

@charangowdamd-cmd what is different in your PR then we have in:

@charangowdamd-cmd

Copy link
Copy Markdown
Contributor Author

@slawekjaranowski
Thanks for pointing this out. After comparing both PRs, I can see that #13480 already covers the same fix for the maven-3.10.x branch. My intention was to contribute the fix for this issue, but I missed the existing PR. Sorry for the duplication. I'll close my PR to avoid duplicate work. Thank you for the clarification.

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.

3 participants