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>
My linked in profile