Maven 2 Inherit Plugin: Usage

Adding the Inherit Plugin to your build

To use the current release in your plugin project, all you need to add is:

  <build>
    <plugins>
      <plugin>
        <groupId>org.ops4j</groupId>
        <artifactId>maven-inherit-plugin</artifactId>
        <version>1.1</version>
        <executions>
          <execution>
            <goals>
              <goal>inherit</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

Extending a goal from an existing plugin

/**
 * @extendsPlugin eclipse
 * @goal eclipse
 * @phase package
 */
public class EclipseOSGiMojo extends EclipsePlugin
{
   // NOTE: if your plugin has a field with the same name as a private field in the inherited mojo
   // (ie. it's hiding the original field) then your new field will be injected with the parameter
   // value, not the one from the original mojo.

   // You'll then need to push the value into the hidden field, either with a setter (if available)
   // or by reflection. To access private fields with reflection, you should use "setAccessible" on
   // the reflected field. An example of this can be seen in the maven-pax-plugin code.
}

Extending a different goal from an existing plugin

/**
 * @extendsPlugin archetype
 * @extendsGoal create
 * @goal create-project
 * @requiresProject false
 */
public class OSGiProjectArchetypeMojo extends MavenArchetypeMojo
{
   // See the "maven-pax-plugin" code for other examples.
}

NOTE: extended plugins should be added as dependencies to your pom

    <dependency>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-eclipse-plugin</artifactId>
      <type>maven-plugin</type>
      <version>2.5.1</version>
    </dependency>

The dependency type has to be set to "maven-plugin" for Maven plugins.