I'm trying to develop a maven plugin and it does not work when I use @Parameter annotation.
My dependencies:
...
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>3.2.3</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.3</version>
</dependency>
...
When I use:
@Parameter (property = "resources")
protected String resources;
resources are kept as null, and when I change it with:
/**
* @parameter expression="${resources}"
*/
protected String resources;
resources get fulfilled. I execute my plugin as:
mvn example:goal -Dresources=whatever
And this is my Mojo declaration:
@Mojo(name = "example", defaultPhase = LifecyclePhase.PROCESS_RESOURCES)
public class ExampleMojo extends AbstractMojo {
Any ideas why does this happens and what do I have to do to get this annotation working as expected?
Well, I had two problems. One cause by me and one a known bug solved in a newer version of mvn than the one installed here.
First the problem caused by me: Actually my Mojo declaration was this:
This made my plugin work due to the comments with @goal and @phase. SO I thought @Mojo was doing the job, but I was wrong.
The second issue is this known bug: http://jira.codehaus.org/browse/MNG-5346
There are a few solutions, like adding maven-plugin-plugin dependency and a few descriptors to the mojo's pom. But I chose to update my maven to 3.2.3 and removed the annotated comments (@goal and @phase) and everything started to work as expected.
Now my mojo looks like this:
And for the sake of completeness this is my pom: