gnodet-bot commented on code in PR #13910:
URL: https://github.com/apache/maven/pull/13910#discussion_r4526382465
##########
impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/mvn/MavenInvoker.java:
##########
@@ -139,6 +140,18 @@ protected void postCommands(MavenContext context) throws
Exception {
logger.info("Enabling strict checksum verification on all artifact
downloads.");
}
+ // --list-aliases: print effective aliases and exit
+ if (context.options().listAliases().orElse(false)) {
+ Map<String, List<String>> aliases = context.effectiveAliases;
+ if (aliases == null || aliases.isEmpty()) {
+ logger.info("No build aliases defined in any settings file.");
+ } else {
+ logger.info("Effective build aliases:");
+ aliases.forEach((name, args) -> logger.info(" " + name + " ->
" + String.join(" ", args)));
+ }
+ throw new InvokerException.ExitException(0);
+ }
Review Comment:
⚠️ **Alias expansion is missing.** This block handles `--list-aliases`, but
nothing in the PR actually expands aliases during a normal build. The PR body
says `MavenInvoker.expandAliases()` replaces CLI arguments with alias token
lists, and the model Javadoc says *"every argument on the command line is
checked against alias names in order; each match is replaced in-place"* — but
`expandAliases()` is not in this diff.
`context.effectiveAliases` is populated but never consulted when processing
build goals. Running `mvn ci` will not expand to `mvn verify
-Dmaven.test.skip=true`; it will fail with "No plugin found for prefix 'ci'".
The `<aliases>` section is effectively a no-op for real builds in this PR.
##########
impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/mvn/MavenInvoker.java:
##########
@@ -149,6 +162,56 @@ protected void postCommands(MavenContext context) throws
Exception {
}
}
+ @Override
+ protected void customizeSettingsResult(MavenContext context,
SettingsBuilderResult settingsResult)
+ throws Exception {
+ // Collect aliases: installation < user < project (last-wins / project
overrides)
+ // EffectiveSettings merge order is project→user→installation
(first-wins in merge),
+ // so we build manually to get last-wins from project.
+ Map<String, List<String>> aliases = new java.util.LinkedHashMap<>();
+ addAliases(aliases, settingsResult.getInstallationSettings());
+ addAliases(aliases, settingsResult.getUserSettings());
+ addAliases(aliases, settingsResult.getProjectSettings());
+ context.effectiveAliases = aliases.isEmpty() ? null :
java.util.Collections.unmodifiableMap(aliases);
+
+ // Phase injections: project-scoped only; user/installation <phases>
are silently ignored.
+ List<org.apache.maven.api.settings.PhaseInjection> phases =
+ settingsResult.getProjectSettings().getPhases();
+ context.projectPhases =
+ (phases != null && !phases.isEmpty()) ?
java.util.Collections.unmodifiableList(phases) : null;
+
+ // Warn if user or installation settings define <phases> (not
supported at those tiers)
+ warnIfPhasesDefinedOutsideProject(context,
settingsResult.getUserSettings(), "user");
Review Comment:
Two issues with this warning:
1. **Duplicate.** `DefaultSettingsValidator.validate()` already emits
`BuilderProblem.Severity.WARNING` ("is not supported on user or installation
settings") for the same condition at settings-load time. This `logger.warn()`
fires again at session-init time — the user sees two messages about the same
problem.
2. **Not actionable for installation settings.** The `installation` tier is
owned by the Maven distribution / sysadmin, not the developer running the
build. Emitting `WARN` for something the user cannot fix violates the
apache/maven convention that warnings must be actionable. Use
`context.logger.debug()` for the installation tier (or suppress it entirely and
rely on the validator warning).
Suggested fix: remove `warnIfPhasesDefinedOutsideProject` entirely and rely
on the validator-level `BuilderProblem.WARNING` that already fires at load
time. The validator warning is already correctly scoped to user and
installation settings.
--
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]