从自定义Mojo访问Maven插件的运行时配置的最佳方法? [英] Best way to access the runtime configuration of a maven plugin from a custom mojo?
问题描述
我正在编写一个自定义的maven2 MOJO.我需要从此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?
推荐答案
您可以使用以下步骤获取当前在构建中使用的插件的列表:
You can get a list of plugins currently been used in the build using the following steps:
首先,您需要让Maven将当前项目注入到mojo中,然后使用下面定义的类变量来获取它.
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.
最后,您可以将其配置为Xpp3Dom.
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.
这篇关于从自定义Mojo访问Maven插件的运行时配置的最佳方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!