gnodet opened a new pull request, #13269:
URL: https://github.com/apache/maven/pull/13269

   ## Problem
   
   When a user types `mvn` without any arguments and there is no `pom.xml` in 
the current directory, Maven currently fails with:
   
   ```
   [ERROR] No goals have been specified for this build. You must specify a 
valid lifecycle phase or a goal...
   [ERROR] BUILD FAILURE
   ```
   
   This is surprising and unhelpful — especially for new users. Tools like 
`java` and `javac` print usage in this situation.
   
   The discussion on the dev list (["Print usage when no arguments are 
given"](https://lists.apache.org/thread/...) Sep 2026) confirmed broad 
agreement that the current behavior should be improved, with the key constraint 
that default goals must still work.
   
   ## Solution
   
   Override `postCommands()` in `MavenInvoker` to detect the following narrow 
condition:
   
   1. **No goals or lifecycle phases were given** on the command line.
   2. **No POM file is present** in the current directory (or via `-f`).
   
   When both are true, print the same help output as `mvn -h` and exit with 
code 0.
   
   If a POM is found, Maven proceeds as before: the default goal (if any) is 
executed, or `NoGoalSpecifiedException` is reported as today. **Existing 
behavior for all normal project builds is unchanged.**
   
   ## Why this approach
   
   - **No shell script changes needed** — shell-script patching would break 
default goals and require identical changes to `mvn.cmd`, `mvnDebug`, etc.
   - **No full model resolution** — we reuse `determinePom()` which is a cheap 
file-existence check via `ModelProcessor.locateExistingPom()`. No parent POM 
downloads, no DI warmup.
   - **Right hook point** — `postCommands()` fires after `lookup()` (DI is 
ready, `context.lookup` is available), so `determinePom()` can be called safely.
   - **Consistent exit code** — exits 0, matching the `mvn -h` convention.
   


-- 
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]

Reply via email to