Home > My Work > How to extends a jar packaged maven plugin

How to extends a jar packaged maven plugin

I’ve used this plugin to extend dependency plugin’s copy-dependency goal.

This is my mojo

/**
 * @extendsPlugin dependency
 * @extendsGoal copy-dependencies
 * @goal deploy-env-lib
 * @requiresDependencyResolution test
 * @aggregator
 */
public class DeployEnvironmentLibMojo extends CopyDependenciesMojo{

    /**
     * La home di JBoss.
     *
     * @parameter expression="${jboss.home}"
     * @required
     */
    protected String jbossHome;

    /**
     * Il nome del server JBoss.
     *
     * @parameter expression="${jboss.serverName}"
     * @required
     */
    protected String jbossServerName;

    /**
     * POM
     *
     * @parameter expression="${project}"
     * @readonly
     * @required
     */
    protected MavenProject project;

    public void execute() throws MojoExecutionException {
        getLog().info("------------------------------------------------------------------------");
        getLog().info("DEPLOY-ENV-LIB");
        getLog().info("------------------------------------------------------------------------");
        super.outputDirectory=this.outputDirectory;
        super.overWriteReleases=this.overWriteReleases;
        super.overWriteSnapshots=this.overWriteSnapshots;
        super.overWriteIfNewer=this.overWriteIfNewer;
        super.includeScope=this.includeScope;
        super.excludeGroupIds=this.excludeGroupIds;
        super.excludeArtifactIds=this.excludeArtifactIds;
        super.project=this.project;
        super.repositoryFactory=this.repositoryFactory;
        super.installer=this.installer;
        super.factory=this.factory;
        super.resolver=this.resolver;
        super.remoteRepos=this.remoteRepos;
        super.copyPom=this.copyPom;
        super.execute();

    }
}

My mojo extends dependency plugin’s CopyDependenciesMojo, inheriting its properties.
These declarations:

* @extendsPlugin dependency
* @extendsGoal copy-dependencies

are maven-inherit-plugin specific. With the help of these instructions maven-inherit-plugin merges the plugin.xml files exposing inherited properties.

Without this code

super.outputDirectory=this.outputDirectory;
super.overWriteReleases=this.overWriteReleases;
super.overWriteSnapshots=this.overWriteSnapshots;
super.overWriteIfNewer=this.overWriteIfNewer;
super.includeScope=this.includeScope;
super.excludeGroupIds=this.excludeGroupIds;
super.excludeArtifactIds=this.excludeArtifactIds;
super.project=this.project;
super.repositoryFactory=this.repositoryFactory;
super.installer=this.installer;
super.factory=this.factory;
super.resolver=this.resolver;
super.remoteRepos=this.remoteRepos;
super.copyPom=this.copyPom;

the program won’t work correctly. It seems like the parameters injection doesn’t work correctly with superclasses…

These are the new entries in my plugin pom:

   <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>
    <dependencies>
        <dependency>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <type>maven-plugin</type>
            <version>2.2</version>
        </dependency>
    </dependencies>
Advertisements
Categories: My Work
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: