Hi all, Thanks for the discussion — I think the right path is now clear.
Gary's point is correct: printing help unconditionally when no args are given would break projects that rely on a default goal. The shell-script approach Björn suggested (prepending `-h` when `$# -eq 0`) is too blunt for exactly that reason — and it would need identical changes to mvn.cmd, mvnDebug, and so on. Tamás identified the real constraint: detecting a default goal requires building the full project model (parent POM resolution etc.), which is expensive and happens well after the very early `-h` path. So we can't do it there. Gerd's proposal is the right framing: - POM present with default goal → execute it (unchanged today) - No POM and no goals → print usage I've implemented exactly that in MavenInvoker.postCommands(), which fires after DI is fully initialized (so ModelProcessor is available) but before the build executes. The check reuses the existing determinePom() call — a cheap file-existence probe via ModelProcessor.locateExistingPom(), no resolution involved. When both conditions hold (no goals specified AND no POM found), we print the same help as `mvn -h` and exit 0. On Björn's second point: the duplicate error message when -f points to a missing POM is also fixed in the same PR. The root cause was a double-print: the mvn shell script's find_file_argument_basedir() already validates the -f argument and prints an error, but the `exit 1` was inside a subshell, so it didn't stop the main script from launching the JVM, which then printed the same message again through the Java logging infrastructure. The fix propagates the subshell exit code through find_maven_basedir() and bails out before launching the JVM. The error now appears exactly once, with the standard [ERROR] prefix. PR: https://github.com/apache/maven/pull/13269 Regards, Guillaume Le jeu. 24 sept. 2026 à 13:53, Björn Raupach <[email protected]> a écrit : > > If the execution of a default goal requires a pom.xml then we have an > chicken-and-egg situation. > > I am honest, I didn't know default goals exists. First time I have heard > of them. > > But since this went into straight into a technical discussion I assume > no one sees a problem with my problem of the usability. > > The java as well as the javac command require arguments to do anything. > If you do not provide something, they print a usage instead. mvn is part > of that ecosystem. Its behaviour should match. That is my point. > > I would suggest the quick fix in mvn.sh and mvn.cmd. Print usage if > there is no argument. > > By the way If I use mvn with -f flag and point to an non-existing > pom.xml file I get: > > mvn -f Development/pom.xml > POM file Development/pom.xml specified with the -f/--file command line > argument does not exist > POM file Development/pom.xml specified with the -f/--file command line > argument does not exist > > This does not result in a build failure. Inconsistent behavior. > > No idea why the message is printed twice. > > > with kind regards > Björn > > Am 18.09.2026 09:37 schrieb Tamás Cservenák: > > Howdy, > > > > The `mvn -h` runs _very early_, when not even DI is set up (or is, but > > partially). > > To detect if there is any "default" goal set, the model of the current > > project must be built (and this may include resolution, like an > > external parent of the project POM and so on). > > At this point, when there is no use specified goal, nor project > > "default" goal set, yes, we could do something smarter, maybe even > > just fall back to -h? > > > > > > > > On Wed, 16 Sept 2026 at 12:48, Mirko Friedenhagen > > <[email protected]> wrote: > >> > >> Maybe maven-core could include a plugin with _one_ mojo called > >> cli-help which could be defined as default goal, then? > >> > >> Mit freundlichen Grüßen > >> Mirko Friedenhagen > >> — > >> > >> > >> > Am 08.09.2026 um 16:09 schrieb Gary Gregory <[email protected]>: > >> > > >> > If you run mvn without args, then Maven runs the default goal, so it > >> > should > >> > NOT print help. You could argue that the message should be clearer if > >> > there > >> > are no args AND there is no default goal. > >> > > >> > 2c, > >> > Gary > >> > > >> > On Tue, Sep 8, 2026, 09:44 Björn Raupach <[email protected]> wrote: > >> > > >> >> Hello Apache Maven developers, > >> >> > >> >> I'm looking for an explanation of a behaviour in Maven that I'm still > >> >> unclear about. > >> >> > >> >> If I type the mvn command without any arguments I get an BUILD FAILURE. > >> >> > >> >> What I consider the better option is printing the usage or help instead. > >> >> The output I am getting when executing mvn -h. > >> >> > >> >> In my humble opinion, this is a quick fix and a small, yet notable, > >> >> improvement to usability for command line users. > >> >> > >> >> Something like this in the mvn shell script just before the final exec. > >> >> > >> >> if [ "$#" -eq 0 ]; then > >> >> set -- "-h" > >> >> fi > >> >> > >> >> kind regards > >> >> Björn > >> >> > >> >> > >> >> --------------------------------------------------------------------- > >> >> To unsubscribe, e-mail: [email protected] > >> >> For additional commands, e-mail: [email protected] > >> >> > >> >> > >> > >> > >> --------------------------------------------------------------------- > >> To unsubscribe, e-mail: [email protected] > >> For additional commands, e-mail: [email protected] > >> > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: [email protected] > > For additional commands, e-mail: [email protected] > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > -- ------------------------ Guillaume Nodet --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
