gnodet-bot commented on code in PR #13511:
URL: https://github.com/apache/maven/pull/13511#discussion_r4271216936
##########
maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java:
##########
@@ -642,6 +642,19 @@ 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.
+ List<String> goals = cliRequest.commandLine.getArgList();
+ if (goals.isEmpty() && modelProcessor != null) {
+ File pom = modelProcessor.locatePom(new
File(cliRequest.workingDirectory));
Review Comment:
⚠️ **Bug: `-f` flag ignored by this POM-existence check**
This lookup uses `cliRequest.workingDirectory` unconditionally. When a user
runs `mvn -f /other/project` from a directory without a `pom.xml`, this branch
will print help and exit 0 instead of building the project at the `-f` path.
The check should be skipped (or the POM resolved from the alternate path)
when `ALTERNATE_POM_FILE` (`-f` / `--file`) is present on the command line:
```suggestion
File pom =
cliRequest.commandLine.hasOption(CLIManager.ALTERNATE_POM_FILE)
? modelProcessor.locatePom(new
File(cliRequest.commandLine.getOptionValue(CLIManager.ALTERNATE_POM_FILE)))
: modelProcessor.locatePom(new
File(cliRequest.workingDirectory));
```
Or, more simply, skip the entire check when `-f` is set:
```java
if (goals.isEmpty() && modelProcessor != null
&& !cliRequest.commandLine.hasOption(CLIManager.ALTERNATE_POM_FILE))
{
```
--
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]