Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to access the runtime configuration of a maven plugin from a custom mojo?

I am writing a custom maven2 MOJO. I need to access the runtime configuration of another plugin, from this MOJO.

What is the best way to do this?

like image 279
npellow Avatar asked Sep 24 '08 04:09

npellow


1 Answers

You can get a list of plugins currently been used in the build using the following steps:

First you need to get Maven to inject the current project into your mojo, you use the class variable defined below to get this.

/**
 * The maven project.
 * 
 * @parameter expression="${project}"
 * @readonly
 */
 private MavenProject project;

Then you can use the following to get a list of plugins used in this build.

mavenProject.getBuildPlugins()

You can iterate though this list until you find the plugin from which you want to extract configuration.

Finally, you can get the configuration as a Xpp3Dom.

plugin.getConfiguration()

Note: If your altering the other plugins configuration (rather than just extracting information), it will only remain altered for the current phase and not subsequent phases.

like image 156
Kingamajick Avatar answered Oct 21 '22 19:10

Kingamajick