Apache Maven Create a Maven Plugin Using plugin configuration

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

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


Got any Apache Maven Question?