Plugins can be configured by annotating fields with @Parameter
. The MOJO is then injected with the configuration.
@Mojo(name = "greet")
public final class GreetMojo extends AbstractMojo {
@Parameter(required = true)
public String name;
public void execute() throws MojoExecutionException, MojoFailureException {
getLog().info("Hello " + name);
}
}
The name
parameter can be configured in the POM:
<plugin>
<groupId>com.mattunderscore</groupId>
<artifactId>hello-world-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<configuration>
<name>Matt</name>
</configuration>
</plugin>
If the greet
goal is run as a standalone goal the name
parameter can be defined as property on the command line:
mvn <plugin name>:greet -Dname=Geri