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 ?
A Project Object Model or POM is the fundamental unit of work in Maven. It is an XML file that contains information about the project and configuration details used by Maven to build the project. It contains default values for most projects.
model version is the version of project descriptor your POM conforms to. It needs to be included and is set. The value 4.0. 0 just indicated that it is compatible Maven 3.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With