Passing parameters to Custom Lifecycle from a mojo
i have written a custom maven plugin which extends the axis2 wsdl2java plugin with the concept of creating custom lifecycle where the wsdl开发者_运维问答2java plugin is executed before goal of my custom plugin is executed.
The code for invoking the custom lifecycle is as follows.
lifecycle.xml
<lifecycles>
<lifecycle>
<id>custom-lifecycle</id>
<phases>
<phase>
<id>invoke</id>
<executions>
<execution>
<goals>
<goal>
org.apache.axis2:axis2-wsdl2code-maven-plugin:wsdl2code
</goal>
</goals>
<configuration>
<packageName>com.foo.myservice</packageName>
<wsdlFile>src/main/wsdl/myservice.wsdl</wsdlFile>
</configuration>
</execution>
</executions>
</phase>
</phases>
</lifecycle>
</lifecycles>
My Mojo is
/**
*
* @goal process
* @execute lifecycle="custom-lifecycle" phase="invoke"
*/
public class SampleMojo extends AbstractMojo
{
public void execute()
throws MojoExecutionException
{
//Code
}
}
Problem:I want to pass the parameters of wsdl2java plugin (i.e,packagename,wsdlFile) from my custom plugin.
Is it possible to send the parameters from my Mojo to custom lifecycle? If so how to do it?
Thanks in Advance
Aadhya
Yes, this is indeed possible, and is achieved by annotating static fields with the same name as the xml parameter with @param as follows:
/**
* Package name - this is injected from the 'packageName' xml element
* @parameter
*/
private static String packageName;
/**
* WSDL File Location, populated from the 'wsdlFile' xml element
* @parameter
*/
private static String wsdlFile;
public void execute() throws MojoExecutionException, MojoFailureException {
//do stuff here with packageName and wsdlFile.
}
PS: Checkstyle has a problem with @goal and @parameter - I had to turn off checkstyle using //CSOFF: TreeWalker to disable it completely for this class.
精彩评论