2

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

Hello_world
  • 303
  • 2
  • 11
  • Although I don't know Maven very well yet, the step from version 2 to 3 was a big leap (you can take a look at [this question](http://stackoverflow.com/q/3157240/3127111)). I think you should upgrade your plugins as soon as possible. Being a major version change, I suppose some incompatibilities could be there. – watery Jan 22 '15 at 12:10
  • @watery Upgrading this plugin is not a possibility as we should still be able to run it with Maven2 components, the best way would be to find how to solve this problem or to find another solution which works for Maven2 and 3. We could make a Maven3 branch as someone in my company told me, but we'll run into maintenance problems. Sadly enough, Maven's documentation is really scarce about plugins so I am a bit stuck here – Hello_world Jan 22 '15 at 12:18
  • You need to change your plugin otherwise you won't get it working under Maven 3 – khmarbaise Jan 22 '15 at 15:04

2 Answers2

1

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.

khmarbaise
  • 92,914
  • 28
  • 189
  • 235
  • I am not the one who made this plugin in the first place, I guess the developer might have forgotten the final keyword or something like that, anyway this is **not at all** my primary concern. Changing the xdocklet to the Java 5 format is not changing anything and the value ${project} is indeed referenced in the documentation. Additionally, you are not responding to my primary question, which is **WHY** this not working anymore. `give a man a fish and you feed him for a day; teach a man to fish and you feed him for a lifetime` – Hello_world Jan 23 '15 at 09:52
  • If you like me to solve your problem i need the full code so could take a look. – khmarbaise Jan 23 '15 at 11:43
0

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.

Hello_world
  • 303
  • 2
  • 11