Reputation: 303
Please note that I am AWARE of the fact that Maven2 is EOL, but I have no word on the choices made on the production side, so please stop telling me to switch to Maven3 as this is not answering this question in any ways.
Right now we are using Maven2 in our company, but for some reasons some of our components needs that we use Maven3.
The plugin I am working on is used by all the components (by being in the parent pom) and gives an error when run with the Maven3 components.
[ERROR] Failed to execute goal XXXX on project YYY: Unable to parse
configuration of mojo XXX for parameter project: Cannot find 'project' in class X.
"project" being declared as :
/**
* The Maven project.
*
* @since 2.0.2
* @parameter expression="${project}"
* @required
* @readonly
*/
private static MavenProject project;
And used as such (in Execute() ):
LOGGER.info("==> Running XXX plugin for projet='{}'.",
project.getArtifactId());
It was working like a charm in Maven2
As far as I understand, no parameters are given to the instance project of the object "MavenProject".
The question is why was the expression getting the right informations in the pom in Maven2 but not anymore in Maven3 ?
To add more informations and be more precise, here is the inherited profile from the super pom :
<profile>
<id>profileID</id>
<build>
<plugins>
<plugin>
<groupId>com.XXX</groupId>
<artifactId>maven-XXX-plugin</artifactId>
<executions>
<execution>
<phase>test-compile</phase>
<goals>
<goal>modelmanager</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
To me, this is not the root of any issue as nothing but phases and goals are provided here, but I still provide it for better understanding.
If that can help, there is no versions specified in the pom for the maven plugin "plugin".
The execution is done as such :
mvn [clean] [a phase] -PprofileID
Upvotes: 2
Views: 298
Reputation: 303
The error was coming from :
private static MavenProject project;
Removing static and keeping everything else untouched fixed the issue
So, it seems they changed the way Mojos works in Maven3 and, the attribute being static, it was not getting any value for some reason.
Maybe some answer by looking at how JVM internals works : http://blog.jamesdbloom.com/JVMInternals.html#classloader
The static field may have been declared (and not initialized) BEFORE Maven start parsing the annotations.
That being said, I do not know why there was a static declaration for the field in the first place, so because it was working in Maven2, I assumed it was not the problem.
Upvotes: 0
Reputation: 97359
There are two issues with your approach. First you are using static
which is wrong under any circumstances.. Furthermore you should change to Java 5 annotations instead of the old xdoclet way which you can do like the following.
@Parameter (defaultValue = "${project}", required=true, readonly = true)
private MavenProject project;
Knowing which values can be defined can be found in evaluation reference.
If you do it correct the plugin will work for Maven 2 and for Maven 3. Apart from that Maven 2 has been defined End Of Life and Maven 3 is been there for a long time (since 2010 !).
You should be aware of the plugin tools which can support you there.
Upvotes: 1