Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Maven MOJO - getting information from project POM

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 ?

like image 607
Xeperis Avatar asked May 15 '12 18:05

Xeperis


People also ask

Does POM xml contains metadata about the project?

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.

What is Modelversion in POM xml?

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.


1 Answers

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> 
like image 87
Jörn Horstmann Avatar answered Oct 04 '22 06:10

Jörn Horstmann