A Complete Example

The following complete example demonstrates how to use the meta-maven-plugin-maven-plugin to generate a meta-plugin that wraps the echo-maven-plugin and exposes a configurable parameter.

Building the Meta-Plugin

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>io.github.rmichela</groupId>
    <artifactId>echo-meta-maven-plugin</artifactId>
    <version>1.0.2</version>
    <packaging>maven-plugin</packaging>

    <name>Meta-Maven-Plugin Demo-Plugin</name>

    <properties>
        <maven.compiler.release>11</maven.compiler.release>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.api.version>3.9.9</maven.api.version>
        <maven.plugin.toolchain.version>3.15.1</maven.plugin.toolchain.version>
    </properties>

    <!-- Required dependencies for Maven Plugin development -->
    <dependencies>
        <!-- Maven Plugin API -->
        <dependency>
            <groupId>org.apache.maven</groupId>
            <artifactId>maven-plugin-api</artifactId>
            <version>${maven.api.version}</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.apache.maven</groupId>
            <artifactId>maven-core</artifactId>
            <version>${maven.api.version}</version>
            <scope>provided</scope>
        </dependency>

        <!-- Maven Annotations for Plugin Development -->
        <dependency>
            <groupId>org.apache.maven.plugin-tools</groupId>
            <artifactId>maven-plugin-annotations</artifactId>
            <version>${maven.plugin.toolchain.version}</version>
            <scope>provided</scope>
        </dependency>

        <!-- Mojo Executor library -->
        <dependency>
            <groupId>org.twdata.maven</groupId>
            <artifactId>mojo-executor</artifactId>
            <version>2.4.1</version>
            <scope>compile</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <!-- The meta-maven-plugin-maven-plugin itself -->
            <plugin>
                <groupId>io.github.rmichela</groupId>
                <artifactId>meta-maven-plugin-maven-plugin</artifactId>
                <version>1.0.2</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>meta-meta-plugin</goal>
                        </goals>
                    </execution>
                </executions>
                
                <!-- Declarative meta-plugin configuration for building the meta-plugin -->
                <configuration>
                    <!-- Documentation strings to include in javadoc and the generated Maven site -->
                    <documentation>
                        <overall>An example meta-maven plugin.</overall>
                        <phases>
                            <initialize>Prints a message during the Initialize phase.</initialize>
                        </phases>
                    </documentation>
                    
                    <!-- Plugin parameters for the meta-plugin -->
                    <parameters>
                        <parameter>
                            <name>greeting</name>
                            <defaultValue>Hello World</defaultValue>
                        </parameter>
                    </parameters>
                    
                    <!-- The embedded plugin configuration to execute when the meta-plugin is run -->
                    <plugins>
                        <plugin>
                            <groupId>com.github.ekryd.echo-maven-plugin</groupId>
                            <artifactId>echo-maven-plugin</artifactId>
                            <version>2.0.0</version>
                            <executions>
                                <execution>
                                    <goals>
                                        <goal>echo</goal>
                                    </goals>
                                </execution>
                            </executions>
                            <configuration>
                                <!-- A reference to a meta-plugin parameter defined above -->
                                <message>@{greeting}</message>
                            </configuration>
                        </plugin>
                    </plugins>
                </configuration>
            </plugin>
            
            <!-- The maven-plugin-plugin is part of the maven plugin development toolchain -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-plugin-plugin</artifactId>
                <version>${maven.plugin.toolchain.version}</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>helpmojo</goal>
                            <goal>descriptor</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

This configuration will generate a meta-plugin that exposes a greeting parameter, and executes the embedded echo plugin during it's default phase.

Consuming the Meta-Plugin

Consuming the meta-plugin in a project would look like this:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>io.github.rmichela</groupId>
    <artifactId>using-echo-plugin</artifactId>
    <version>1.0.2</version>

    <properties>
        <maven.compiler.release>11</maven.compiler.release>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <greeting>Hello Maven</greeting>
    </properties>

    <build>
        <plugins>
            <!-- Execute the meta-plugin, with a parameter value sourced from the project properties -->
            <plugin>
                <groupId>echo-plugin-group</groupId>
                <artifactId>echo-meta-maven-plugin</artifactId>
                <version>1.0.2</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>initialize</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <greeting>${greeting}</greeting>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>