Understanding command-line options in Maven

While the most popular way to run Maven is to specify goals, Maven provides a number of command-line options to customize its behavior. They range from specifying values for properties, to varying the verbosity of the Maven output. It is useful to know some of the arguments, as they will often help with troubleshooting issues with Maven.

Getting ready

Maven is set up on your system and is verified as working.

How to do it...

To understand command-line options in Maven, perform the following steps:

  1. Open the command prompt.
  2. Run the following command:
    mvn –h
    
  3. You will see an output such as the following screenshot:
    How to do it...

A number of options that Maven supports are displayed in the preceding screenshot.

How it works...

We will briefly discuss the command-line options that Maven provides.

Options

When there is an error while running Maven, this flag will result in Maven displaying a detailed stack trace of the error:

-e –errors

When the quiet option is enabled, only errors are displayed. The other outputs are not printed. This permits speeding up builds where verbose outputs are usually displayed:

-q –quiet

We have seen the version option to display the Maven version in the first three recipes of Chapter 1, Getting Started. This is also a simple way to check if Maven is installed and working:

-v –version

When invoked with the offline option, Maven does not attempt to download any dependency or plugin from the Internet. This option will work correctly, provided Maven has all the information required for the project to be built and run. We will see how to enable projects to run in offline mode:

-o –offline

When enabled with the debug option, Maven prints a lot of verbose output about every step that it performs. This is typically used to troubleshoot any build issues:

-X –debug
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.224.56.29