GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — feat: extend settings.xml with CLI defaults, extensions, aliases and lifecycle phases (v2.1.0) by gnodet · Pull Request #13910 · apache/maven Conversation
Contributor
WhatFolds all reactor-level build configuration into New settings sections (v2.1.0)
ExamplesCLI defaults —
|
| Concern | Today | This PR |
|---|---|---|
| Default CLI args | .mvn/maven.config (flat text, no structure) |
<options> in settings |
| Core extensions | .mvn/extensions.xml (separate file) |
<extensions> in settings |
| Command shortcuts | (none — teams use Makefiles or shell aliases) | <aliases> in settings |
| Custom lifecycle phases | (requires a full extension) | <phases> in settings |
Folding everything into settings means:
.mvn/settings.xml is the single source of truth for reactor behavioursettings.mdo (maven-api-settings)Extended to v2.1.0 with new classes SettingsExtension, Alias, and PhaseInjection. All coordinate fields on SettingsExtension are XML attributes (compact syntax). The <alias> inline form uses xml.content="true" on the content field — the reader template now calls parser.getElementText() instead of parsing a child element, while the writer emits serializer.writeCharacters(). The <options> element uses xml.format="mixed" with <arg> children for structured form.
MavenParser reads project .mvn/settings.xml early (before DI) and:
<options> tokens to the CLI argument list<extensions> as core extensions (falls back to extensions.xml when absent)MavenInvoker.expandAliases() performs alias expansion: each CLI argument is looked up in the merged alias map and replaced by its token list. ArgumentTokenizer handles shell-style quote parsing for the inline form.
--list-aliases prints the effective alias table and exits.
LifecycleProcessor (maven-api-spi)New @Consumer SPI interface:
Lifecycle process(Lifecycle lifecycle);
Called for each lifecycle at session init; processors chain (output of one feeds the next). Implementations must be stateless.
SettingsLifecycleProcessor + PhaseEnrichedLifecycleSettingsLifecycleProcessor reads <phases> from the invoker request and delegates to PhaseEnrichedLifecycle, which inserts phases into the lifecycle DAG. DefaultLifecycles and BuildPlanExecutor apply the processor chain at all lifecycle resolution sites.
<options> → falls back to .mvn/maven.config<extensions> → falls back to .mvn/extensions.xmlDefaultSettingsValidator warns and drops <extensions>/<phases> found in user or installation tiers| Area | Key files |
|---|---|
| Model | settings.mdo (v2.1.0): SettingsExtension, Alias, PhaseInjection |
| Templates | reader-stax.vm, writer-stax.vm: xml.content="true" and xml.format="mixed" support |
| SPI | LifecycleProcessor.java |
| Parsing | MavenParser (early settings read, alias expansion, extension loading), ArgumentTokenizer |
| Phase injection | SettingsLifecycleProcessor, PhaseEnrichedLifecycle, DefaultLifecycles |
| Validation | DefaultSettingsValidator |
| Tests | ArgumentTokenizerTest, MavenInvokerAliasTest, MavenSettingsOptionsTest, SettingsLifecycleProcessorTest, PhaseEnrichedLifecycleTest |
ArgumentTokenizerTest, MavenInvokerAliasTest (9 cases), MavenSettingsOptionsTest, SettingsLifecycleProcessorTest, PhaseEnrichedLifecycleTestSupersedes: #13249
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Introduces project-scoped settings loaded from `.mvn/settings.xml`, enabling per-project configuration of extensions, lifecycle phase injections, server aliases, and CLI option defaults — all without modifying the user or installation settings. Changes overview: settings model (v2.1.0): - Add `<extensions>` section for declaring core extensions - Add `<aliases>` section for per-server identifier aliases - Add `<phases>` section for injecting custom lifecycle phases - Add `<options>` / `<args>` sections for default CLI arguments - Bump model version to 2.1.0 API additions: - `InvokerRequest`: `aliases()` and `phases()` accessors - `MavenOptions`: `listAliases()` option - `SettingsBuilderResult`: per-tier `getInstallationSettings()`, `getProjectSettings()`, `getUserSettings()` default methods - `LifecycleProcessor` SPI for transforming lifecycles at session init - `Constants`: extension constants with deprecation notes CLI / invoker pipeline: - `BaseParser`: resolve and read project `.mvn/settings.xml` early; load core extensions declared in project settings - `MavenParser`: layer `<options>`/`<args>` from project settings before `maven.config` fallback; `ArgumentTokenizer` ported from the Maven 3 codebase - `LookupContext` / `MavenContext`: per-tier settings fields; `effectiveAliases` and `projectPhases` aggregation - `LookupInvoker`: populate per-tier fields after settings build - `MavenInvoker`: collect server aliases and project phases; handle `--list-aliases`; store phases on `MavenExecutionRequest` Lifecycle integration: - `PhaseEnrichedLifecycle`: decorator that injects custom phases into the lifecycle DAG (ported from reactor-xml branch) - `SettingsLifecycleProcessor`: reads project-scoped phases from the request data map and enriches the default lifecycle - `DefaultLifecycles`: apply `LifecycleProcessor` chain when building the phase-to-lifecycle map - `BuildPlanExecutor`: apply `LifecycleProcessor` chain at all lifecycle resolution sites Validation: - `DefaultSettingsValidator`: warn when `<extensions>` or `<phases>` appear in user or installation settings
- ArgumentTokenizerTest: covers empty input, simple tokens, single/double quotes, backslash escaping, mixed quotes, extra whitespace, and unclosed quote error cases. - SettingsLifecycleProcessorTest: validates the static validate() method — all valid combinations of after/before/parent, and expected IllegalStateException for missing name or missing anchors. - DefaultSettingsValidatorTest: extends existing test with 5 new cases: extensions allowed in project settings, extensions warned in user/installation settings, phases allowed in project settings, phases warned in user/installation settings, both together give 2 warnings. - Fix DefaultSettingsValidator: extensions/phases warnings were incorrectly placed in the 'else' branch of 'if (pluginGroups != null)' instead of a separate 'if (!isProjectSettings)' guard. - Fix BuildPlanCreatorTest + BuildPlanExecutorTest: pass Collections.emptyList() for the new LifecycleProcessor parameter added to BuildPlanExecutor constructor.
- MavenSettingsOptionsTest: covers <options> inline text and <options><arg> structured forms parsed via parseMavenSettingsOptions() - MavenInvokerAliasTest: covers alias inline text and <arg> structured forms, last-wins override across tiers, empty alias removal - Make MavenInvoker.addAliases() package-private for testability
- Fix Constants.java @deprecated: each tier points to its own settings.xml (installation extensions -> installation settings.xml, user -> user settings.xml) - Remove aliases()/phases() from InvokerRequest: they were always empty (populated post-DI in MavenContext, not at parse time); dead API surface removed from InvokerRequest, BaseInvokerRequest, and BaseParser.LocalContext - Fix toCoreExtension() to map Extension.configuration to CoreExtension.configuration (was silently dropped before) - Fix comment in addAliases(): show correct XML <content> child syntax, not bare element text (Modello does not map element text to the content field without xml.content=true) - Update MavenInvokerAliasTest comments to show correct <content> XML syntax
… add PhaseEnrichedLifecycle and process() unit tests
…ates The velocity templates reader-stax.vm and writer-stax.vm lacked support for Modello's xml.content="true" field annotation, which maps a class field to the element body text rather than to a child element. reader-stax.vm: Before the child-element while loop, detect if the class has a content field (XmlFieldMetadata.isContent()). If so, read the element text body via parser.getElementText() directly into that field and skip the while loop entirely. Content fields are also excluded from the child-element switch statement to avoid a spurious case clause. writer-stax.vm: After writing xml.attribute fields, emit writeCharacters() for any content field. Content fields are also excluded from the writeTag() child-element loop to avoid writing a wrapper element. Apply xml.content="true" to the Alias.content field in settings.mdo so that the inline text syntax works as intended: <alias name="ci">verify -Dmaven.test.skip=true</alias> rather than requiring a <content> child element. The structured <arg> form remains available for arguments containing spaces. All 9 MavenInvokerAliasTest tests pass.
… modello templates - settings.mdo: add Alias class with name attribute and args mixed field (xml.itemsStyle="flat", xml.tagName="alias"); add args mixed field to Settings (xml.tagName="options"); add args mixed field to PhaseInjection (xml.tagName="phase-options") - reader-stax.vm: handle body-level mixed-content fields (xml.format="mixed" with no xml.tagName): emit inline-text tokenization or structured <arg> children before the main while-loop; also assign the populated list to the builder after the block - writer-stax.vm: handle mixed-content fields with and without tagName - ArgumentTokenizer: moved to maven-support (settings.v4 package) so it can be shared by the generated SettingsStaxReader and by MavenParser; simplified implementation using StreamTokenizer - MavenParser: use settings.getArgs() / alias.getArgs() directly - MavenInvoker: apply alias expansion at invocation time - Tests: SettingsMixedContentParsingTest (new), MavenSettingsOptionsTest, MavenInvokerAliasTest, ArgumentTokenizerTest updated
- MavenITSettingsOptionsTest: fix loadFile(Path,String,boolean) compile
errors — the 3-arg overload does not exist; use loadFile(getLogFile())
instead. Remove unused IOException/Files imports.
- BaseParser.toCoreExtension(): add isEmpty() checks alongside null
checks for groupId/artifactId/version so that empty-string coordinates
are rejected with the same clear error as null ones.
- DefaultSettingsValidator: validate <phase> declarations eagerly in the
project-settings branch, reporting malformed phases (missing name or
no anchor) as BuilderProblem.Severity.ERROR at settings-load time
instead of letting them surface as IllegalStateException mid-build in
SettingsLifecycleProcessor. Add PhaseInjection import and two new
tests covering both failure modes.
- writer-stax.vm: fix round-trip bug for wrapper mixed-content fields.
Previously $mixedSingularTag was set to the field-level xml.tagName
(e.g. "options"), causing each arg to be written as a sibling
<options>value</options> element directly in the parent — no wrapper,
wrong tag. Fix by distinguishing the two cases:
· Wrapper mixed (xml.tagName set, e.g. Settings.args → <options>):
write the wrapper element, then write items using singular(field.name)
= "arg" as the item tag; skip wrapper when list is empty.
· Body-level mixed (no xml.tagName, e.g. Alias.args): write items
directly in the containing element body, unchanged.
Add four round-trip tests to SettingsMixedContentParsingTest covering
both options and alias in both inline and structured forms (all 16
tests pass).
…SD fix The XSD for <options> and <alias> must carry mixed="true" on their xs:complexType so that IDEs and schema validators accept both the inline text syntax and the structured <arg>-child syntax documented for these fields. The fix is in codehaus-plexus/modello#628 (XsdGenerator: emit mixed="true" for xml.format="mixed" fields). Pin to the SNAPSHOT until that PR is released, then update to 2.8.2.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The 4 new settings sections are well-designed and the test coverage is solid — ArgumentTokenizerTest, SettingsMixedContentParsingTest, SettingsLifecycleProcessorTest, and PhaseEnrichedLifecycleTest cover the core logic. Two things need addressing before merge.
Missing: alias expansion
The PR body explicitly says MavenInvoker.expandAliases() performs alias expansion: each CLI argument is looked up in the merged alias map and replaced by its token list, and the <alias> Javadoc in settings.mdo says Every argument on the command line is checked against alias names in order; each match is replaced in-place by the alias expansion tokens. Neither is true: expandAliases() is not in this diff, and there is no code that substitutes mvn ci → mvn verify -Dmaven.test.skip=true. The alias map is built correctly and --list-aliases works, but the aliases themselves have no effect on actual builds. This is the core user-visible feature of the <aliases> section.
Duplicate warning for <phases> in non-project settings
DefaultSettingsValidator.validate() already emits a BuilderProblem.WARNING ("is not supported on user or installation settings") at settings-load time. warnIfPhasesDefinedOutsideProject() in customizeSettingsResult() then emits a second logger.warn() at session-init time. A user with <phases> in their ~/.m2/settings.xml will see the same concern twice. Remove one of the two (the validator warning is better placed — it fires earlier and uses the standard problem-reporting path).
Additionally, the installation-tier branch of warnIfPhasesDefinedOutsideProject warns a user about something in the Maven installation's own settings — which they typically cannot edit. This should be DEBUG, not WARN.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
… DI in standalone context SettingsLifecycleProcessor is @nAmed and gets discovered by ApiRunner's DI container scan (via META-INF/maven/org.apache.maven.api.di.Inject). In the standalone context used by mvnup tests, LegacySupport is not bound, causing the DI framework to fail when constructing SettingsLifecycleProcessor, which in turn makes ApiRunner.newSession() throw. Mark LegacySupport as @nullable so the DI framework injects null in contexts where it is not available. The existing null-guard in resolveInjections() is extended to cover the null legacySupport case, making the processor a no-op in standalone mode.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Three findings on this PR — one significant, one moderate, one minor.
🔴 Alias expansion not implemented (significant)
The PR builds effectiveAliases (line 947) and stores it in MavenContext, but that map is consumed only by the --list-aliases path (line 920) which prints and exits. No code in this diff performs actual CLI argument substitution/expansion at invocation time. The model documentation says "Every argument on the command line is checked against alias names; each match is replaced in-place" — that behavior is not implemented here.
This means users who define aliases in settings.xml will see them listed via --list-aliases, but the aliases will have no effect when actually invoking Maven. Either the expansion code is planned for a follow-up PR (in which case the model docs should say "not yet active" and --list-aliases should warn), or this needs to be implemented here before merge.
🟡 Potential duplicate warning for <phases> in non-project settings
The same condition triggers two independent warnings:
DefaultSettingsValidator.validate() (line 3370–3376): adds a BuilderProblem WARNING to the problem collectorMavenInvoker.warnIfPhasesDefinedOutsideProject() (line 976–984): emits a logger.warn() directlyWhether the validator's BuilderProblem is actually surfaced to the user depends on LookupInvoker.settings() (outside this diff), but the structural overlap is worth verifying. If both fire on the same input, users will see two warnings for one misconfiguration. Consider whether one of these should be removed or whether the validator warning should be the sole mechanism.
🔵 Missing test for null legacySupport branch in SettingsLifecycleProcessor
Line 1207 has an early-return guard: if (legacySupport == null) { return List.of(); }. The existing test processNoSessionReturnsOriginal (line 1853) tests getSession() == null with a mocked (non-null) LegacySupport, but no test passes null as the legacySupport constructor argument. This guard appears intentional (defensive null handling), so a test covering it would be useful — either add new SettingsLifecycleProcessor(null) in a test or remove the guard if it cannot happen.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Two issues in the integration test resource files: 1. settings-options/precedence: The XML comment contained "--debug" which violates XML well-formedness (double-hyphen not allowed inside comments). This caused the settings builder to fail with a parse error, resulting in exit code 2. 2. settings-extensions: All three test settings.xml files used a wrapper <extensions> element around <extension> children, but the settings model defines extensions with xml.itemsStyle="flat", meaning <extension> elements must appear directly under <settings> without a wrapper. The reader silently skipped the unrecognized <extensions> element, so no extensions were loaded. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
BaseParser.toCoreExtension() builds a CoreExtension from a settings
Extension but did not set location information. When
PrecedenceCoreExtensionSelector logs the selected extensions, it calls
getLocation("").getSource() which throws NullPointerException because
the location was never set.
Set the location to point to the source settings.xml file so that
extension provenance is traceable and the debug logging works.
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Following up on my earlier reviews — the two new commits fix IT test file issues and a CoreExtension NPE, but none of the three findings from the previous review have been addressed.
🔴 Alias expansion still not implemented [NOT addressed]
context.effectiveAliases is built and printed by --list-aliases, but the expansion step — checking each CLI argument against alias names and substituting the token list — is still missing. The model Javadoc on aliases says "every argument on the command line is checked against alias names in order; each match is replaced in-place by the alias expansion tokens", and the PR description shows mvn ci → mvn verify -Dmaven.test.skip=true. Neither is true: mvn ci will fail with "No plugin found for prefix 'ci'". The <aliases> section is a no-op for actual builds.
🟡 Duplicate <phases> warning still present [NOT addressed]
Both sources still fire for user/installation settings with <phases>:
DefaultSettingsValidator.validate() → BuilderProblem.Severity.WARNING ("is not supported on user or installation settings")MavenInvoker.warnIfPhasesDefinedOutsideProject() → context.logger.warn(...) at session-init timeA user will see two warnings for one misconfiguration. The installation tier warning is also not actionable (the user cannot edit it). The suggested fix from my earlier review still stands: remove warnIfPhasesDefinedOutsideProject and rely on the validator warning alone.
🔵 Missing test for null legacySupport constructor [NOT addressed]
d420331 added the @Nullable guard and the if (legacySupport == null) { return List.of(); } branch in resolveInjections(), but no test exercises this path. SettingsLifecycleProcessorTest only tests getSession() == null with a non-null LegacySupport mock — not new SettingsLifecycleProcessor(null). The null-guard is dead code from a testing perspective.
The two new commits (779a3b2, 1566ec8) correctly fix the IT resource files and the BaseParser.toCoreExtension() NPE — those are clean.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…arn on extensions overlap, cache processed lifecycles - MavenInvoker: expand effectiveAliases when setting goals on the execution request so that `mvn ci` (where `ci` is a settings alias) works instead of producing "Unknown lifecycle phase" error. - MavenParser: temporarily set context.options to the already-parsed CLI options before calling resolveProjectSettingsFile() so the --project-settings (-ps) flag is honoured when loading <args>/<options> from project settings. - BaseParser: warn when both settings.xml <extensions> and the legacy extensions.xml coexist, guiding users to migrate. - BuildPlanExecutor: cache the result of processedLifecycles() to avoid re-applying LifecycleProcessors on every call. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.