Get Maven Runtime Status in a Script Shell

I would like to know if there is a way to “request” the Maven runtime from the shell script (used for the build process).

The fact is that I want the entire script assembly to fail as soon as one error appears in one of the Maven shell scripts.

eg.

(0) mvn -f .../someDir clean
(1) mvn -f .../1/pom.xml install
(2) mvn -f .../2/pom.xml -PgenerateWadl

So, if, for example, an error occurs inside (0), then (1) and (2) should no longer be executed, but instead the script assembly should exit with an error message immediately after (0).

I'm not so good at Shell scripts, but I know what $ is? variable to get the return value of earlier execution. But since Maven is simply trying to write errors to the console, this may not work, right?

I would like to research more information about "$?", But for this it is quite difficult to do this.

+3
source share
2 answers

An easy way is to use the option -e.

set -e
mvn -f .../somedir clean
mvn -f .../otherdir install
mvn -f .../thirddir -PgenerateWadl package

This will automatically lead to an error shell if any command in the sequence exits with a non-zero status (if it is not part of an explicit test, such as ifor while, or a chain like that a || b).

You can observe this by inserting a call falsebetween any Maven calls.

For more information, set -esee the setPOSIX Specification .

+5
source
mvn ... && mvn ... && mvn ...

Execution will be performed only if the previous one was successful.

+2

Source: https://habr.com/ru/post/1778703/


All Articles