gnodet-bot commented on code in PR #13511:
URL: https://github.com/apache/maven/pull/13511#discussion_r4276272096
##########
maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java:
##########
@@ -642,6 +642,27 @@ private void commands(CliRequest cliRequest) {
slf4jLogger.info("Enabling strict checksum verification on all
artifact downloads.");
}
+ // If no goals/phases were specified and there is no POM in the
current directory,
+ // print usage (like `mvn -h`) and exit successfully instead of
failing with
+ // "No goals have been specified for this build."
+ // When a POM is present the default goal (if any) may apply, so let
Maven proceed normally.
+ // Skip this check for encryption commands (--encrypt-password,
--encrypt-master-password)
+ // which also have no goals and no POM, but are handled later by
encryption().
+ // Also skip when -f/--file is specified: the alternate POM existence
is validated later,
+ // and the working directory may legitimately have no pom.xml.
+ List<String> goals = cliRequest.commandLine.getArgList();
+ if (goals.isEmpty()
+ && modelProcessor != null
+ &&
!cliRequest.commandLine.hasOption(CLIManager.ALTERNATE_POM_FILE)
+ &&
!cliRequest.commandLine.hasOption(CLIManager.ENCRYPT_PASSWORD)
+ &&
!cliRequest.commandLine.hasOption(CLIManager.ENCRYPT_MASTER_PASSWORD)) {
+ File pom = modelProcessor.locatePom(new
File(cliRequest.workingDirectory));
+ if (!pom.isFile()) {
+ cliManager.displayHelp(System.out);
+ throw new ExitException(0);
+ }
+ }
+
Review Comment:
💡 **Suggestion:** The new help-on-empty behavior (lines 654–665) has no test
coverage in this PR. Consider adding a test to `MavenCliTest` (or equivalent)
that verifies `commands()` calls `cliManager.displayHelp()` and throws
`ExitException(0)` when `goals` is empty, no POM exists, and no `-f`/encryption
options are set. This is the main behavioural change in this PR — a regression
here would be silent.
--
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]