Cover by Sonatype Company

Safari, the world’s most comprehensive technology and business learning platform.

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required

O'Reilly logo

Mojo Parameters

Just as important as the execute() method and the Mojo annotations is the fact that a Mojo is configured via parameters. This section deals with some configuration and topics surrounding Mojo parameters.

Supplying Values for Mojo Parameters

In EchoMojo, we declare the message parameter with the following annotations:

/**
 * Any Object to print out.
 * @parameter
 *       expression="${echo.message}"
 *       default-value="Hello Maven World"
 */
private Object message;

The default expression for this parameter is ${echo.message}. This means that Maven will try to use the value of the echo.message property to set the value for message. If the value of the echo.message property is null, the default-value attribute of the @parameter annotation will be used instead. Instead of using the echo.message property, we can configure a value for the message parameter of the EchoMojo directly in a project’s POM.

We can populate the message parameter in the EchoMojo in a few ways. First, we can pass in a value from the command line like this (assuming that you’ve added org.sonatype.mavenbook.plugins to your pluginGroups):

$ mvn first:echo -Decho.message="Hello Everybody"

We can also specify the value of this message parameter by setting a property in our POM or in our settings.xml:

<project>
  ...
  <properties>
    <echo.message>Hello Everybody</echo.message>
  </properties>
</project>

This parameter can also be configured directly as a configuration value for the plugin. If we wanted to customize the message ...

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required