Java Maven MOJO - getting information from project POM

java, maven, mojo, pom.xml

Solution

You can inject the current maven project into your mojo with a field declared like this:

/**
 * @parameter default-value="${project}"
 * @required
 * @readonly
 */
MavenProject project;

The projects name is then available by simply calling `project.getName()`. To use this API, you need to add the `maven-project` artifact as a dependency:

<dependency>
    <groupId>org.apache.maven</groupId>
    <artifactId>maven-project</artifactId>
    <version>2.0.6</version>
</dependency>

Problem

I am working on a maven plugin. I seem to have a hard time figuring out, what would be a good way to get POM information from project in which you execute the MOJO ? For instance if I execute my mojo in another maven project I would like to get project name or some other parameters. And one more thing, there is a context MAP in AbstractMojo.java class there is private Map pluginContext, could someone correct me if I am wrong but this is suppose to be used for passing information between mojos ?

Original source