GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [3.10.x] Accept the ? optional-profile prefix in -P by slachiewicz · Pull Request #13480 · apache/maven

Conversation

@slachiewicz

@slachiewicz slachiewicz commented Oct 13, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Fixes #13479. Maven 4 reads -P ?id as an optional profile (MNG-7051); Maven 3.10 read ?id as a profile literally named ?id and left id off, so a build passing -P ?run-its to both Maven 3 and 4 silently skipped the profile on Maven 3. The ? is now removed after the +, - and ! prefixes, in the same order as Maven 4, so ?id, +?id, -?id and !?id work; a token that is empty after the prefixes (-P ?, -P -?) is ignored. A missing optional profile still logs the existing "could not be activated" warning, now with the plain id: Maven 3 does not fail on missing profiles, and dropping the warning would need the optional flag on MavenExecutionRequest. The parsing moves into a package-private performProfileActivation, as in Maven 4, so it can be unit tested.

Each token is trimmed before its prefixes are read, as Maven 4 does once #13502 fixes its + check, which read the untrimmed token; empty tokens such as a,,b stay ignored, as in both lines.

All -P sources (the command line, .mvn/maven.config and MAVEN_ARGS) go through this method. maven-3.9.x keeps the old parsing, since that line takes serious bug fixes only.

Verified: a 3.10.1-SNAPSHOT build activates the profile with -P ?run-its where 3.10.0 does not, deactivates it with !?run-its, and succeeds with -P ?missing; mvn -pl maven-embedder test → 43 tests pass, including testOptionalProfiles and testDegenerateProfileTokens.


  • I hereby declare that I have filed an Apache Individual Contributor License Agreement.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@slachiewicz
Accept the ? optional-profile prefix in -P
0f0bc74
Maven 4 reads -P ?id as an optional profile; 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.
@slachiewicz slachiewicz added mvn3 enhancement New feature or request labels Oct 13, 2026
@slachiewicz
slachiewicz marked this pull request as ready for review October 13, 2026 15:44
@slachiewicz slachiewicz added this to the 3.10.1 milestone Oct 13, 2026
gnodet-bot
gnodet-bot suggested changes Oct 13, 2026
View reviewed changes

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

The new performProfileActivation method is missing an isEmpty() guard after stripping all prefixes. Degenerate inputs like -P ?, -P -?, or -P ! strip down to an empty string that is silently inserted into the active/inactive profile list. Maven 4's equivalent method guards each substring call with !profileId.isEmpty() before adding — this backport should do the same.

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread maven-embedder/src/test/java/org/apache/maven/cli/MavenCliTest.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

@slachiewicz
Skip empty profile ids left after the prefixes
cd08f21
gnodet-bot
gnodet-bot approved these changes Oct 13, 2026
View reviewed changes

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Following up on my earlier review — both issues have been addressed.

isEmpty() guard — ✅ addressed. The new commit adds if (profileId.isEmpty()) { continue; } after the ? stripping, which correctly skips empty-string tokens for all degenerate inputs (-P ?, -P -?, -P !?, bare -P -, etc.).

testDegenerateProfileTokens — ✅ addressed. The new test exercises ?,!,+,-,+?,-?,!?, and asserts both active and inactive lists remain empty, which directly validates the guard.

Pre-fix validation: static trace confirms testDegenerateProfileTokens was failing before the fix — token ? strips to "", without the guard activeProfiles.add("") is called, and assertTrue(active.isEmpty()) fails.

LGTM.

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@gnodet

gnodet commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

@slachiewicz why is the difference with the trim kept on purpose ?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@slachiewicz

slachiewicz commented Oct 13, 2026

Copy link
Copy Markdown
Member Author

@slachiewicz why is the difference with the trim kept on purpose ?

The 3.x line has always trimmed each token before reading its +, - or ! prefix; the old code removed by the PR does nextToken().trim(). Maven 4 trims too, and its -/! check reads the trimmed id. Only its + check reads the raw token (token.charAt(0) == '+'), and that looks like a slip rather than a design choice. With -P "a, +b", Maven 4 tries to activate a profile literally named +b. Master has the same check twice in MavenInvoker.java (lines 405 and 432), presumably once for profiles and once for projects. Matching Maven 4 would mean copying that slip into 3.10.

The trim isn’t new: 3.x has always trimmed each token before reading its prefix (the removed nextToken().trim()), and Maven 4 trims too. The difference is only in Maven 4’s + check, which reads token.charAt(0) instead of the trimmed profileId, so -P "a, +b" asks for a profile named +b there while -P "a, -b" deactivates b.

That looks like a slip rather than intent; I can open a PR to make MavenInvoker check profileId on master and 4.0.x so both lines agree.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

slawekjaranowski
slawekjaranowski approved these changes Oct 13, 2026
View reviewed changes
@gnodet gnodet added the bug Something isn't working label Oct 14, 2026
@gnodet

gnodet commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

@slachiewicz why is the difference with the trim kept on purpose ?

The 3.x line has always trimmed each token before reading its +, - or ! prefix; the old code removed by the PR does nextToken().trim(). Maven 4 trims too, and its -/! check reads the trimmed id. Only its + check reads the raw token (token.charAt(0) == '+'), and that looks like a slip rather than a design choice. With -P "a, +b", Maven 4 tries to activate a profile literally named +b. Master has the same check twice in MavenInvoker.java (lines 405 and 432), presumably once for profiles and once for projects. Matching Maven 4 would mean copying that slip into 3.10.

The trim isn’t new: 3.x has always trimmed each token before reading its prefix (the removed nextToken().trim()), and Maven 4 trims too. The difference is only in Maven 4’s + check, which reads token.charAt(0) instead of the trimmed profileId, so -P "a, +b" asks for a profile named +b there while -P "a, -b" deactivates b.

That looks like a slip rather than intent; I can open a PR to make MavenInvoker check profileId on master and 4.0.x so both lines agree.

Yes, that sounds like a good idea.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This was referenced Oct 14, 2026
Read the + prefix of -P and -pl tokens after trimming #13502
Merged
[4.0.x] Read the + prefix of -P and -pl tokens after trimming #13503
Merged
gnodet
gnodet approved these changes Oct 15, 2026
View reviewed changes
@slawekjaranowski slawekjaranowski mentioned this pull request Oct 19, 2026
[Backport maven-3.10.x] Fix #13479: Accept the ? optional-profile prefix in -P #13549
Closed
8 tasks done
@gnodet gnodet changed the title Accept the ? optional-profile prefix in -P [3.10.x] Accept the ? optional-profile prefix in -P Oct 19, 2026
cstamas
cstamas approved these changes Oct 20, 2026
View reviewed changes
@cstamas cstamas linked an issue Oct 20, 2026 that may be closed by this pull request
Accept the ? optional-profile prefix on Maven 3.10 #13479
Closed
@cstamas
cstamas merged commit b6d62df into maven-3.10.x Oct 20, 2026
21 of 22 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@cstamas
cstamas deleted the agent/optional-profiles-3.10 branch October 20, 2026 15:03
@github-actions github-actions Bot assigned cstamas Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@cstamas cstamas cstamas approved these changes
@gnodet gnodet gnodet approved these changes
@slawekjaranowski slawekjaranowski slawekjaranowski approved these changes
+1 more reviewer
@gnodet-bot gnodet-bot gnodet-bot approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@cstamas cstamas

Labels

bug Something isn't working enhancement New feature or request mvn3

Projects

None yet

Milestone

3.10.1

Development

Successfully merging this pull request may close these issues.

Accept the ? optional-profile prefix on Maven 3.10

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@slachiewicz @gnodet @cstamas @slawekjaranowski @gnodet-bot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.