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?
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.
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