如何显示哪个父 pom 包含插件?

How to show which parent pom contains a plugin?

如果我的 pom 是其他 poms 的子层次结构,有没有办法准确显示哪个父 pom 包含插件的定义?

最有可能的简短回答是:否。

根据 Maven 在执行某个构建之前构建模型的方式,Maven Builder Model:

  • 在第 1 阶段,poms 的层次结构得到解决
  • 在第 2 阶段模型规范化和插件配置得到进一步解决
  • 但仅在第 2 阶段结束时才执行有效模型验证,这是在最终有效 pom.xml 文件上完成的,作为合并、覆盖、分析、注入(属性)和依此类推

要查看完整的 pom,maven-help-plugineffective-pom 目标绝对是正确的工具。它将显示(或写入给定文件)构建将使用的最终有效 pom。

插件的完整定义(它的执行、它的全局配置等)只有在我们拥有有效的 pom 后才能创建,因为:

  • 层次结构中任何一点的 pluginManagement 部分都可以影响某个插件
  • 层次结构中任何一点的 plugin 部分也会影响它
  • profiles 在层次结构中的任何一点声明也可以影响它
  • properties,如果用作占位符,也能起到重要作用

看看官方的Maven POM reference,我们可以看到很多入口点影响了某个插件定义,只有在整个pom层次结构中合并后才会对我们的构建有效。定义本身不会有太大帮助,因为它可以 overriden/influenced 在层次结构链上更进一步。


考虑 plugininherited 元素:

true or false, whether or not this plugin configuration should apply to POMs which inherit from this one. Default value is true.

或合并 plugin configuration 个部分:

The default behavior is to merge the content of the configuration element according to element name. If the child POM has a particular element, that value becomes the effective value. if the child POM does not have an element, but the parent does, the parent value becomes the effective value.
You can control how child POMs inherit configuration from parent POMs by adding attributes to the children of the configuration element. The attributes are combine.children and combine.self. Use these attributes in a child POM to control how Maven combines plugin configuration from the parent with the explicit configuration in the child.

或根据 pluginexecution 进一步向下:

inherited: Like the inherited element above, setting this false will supress Maven from passing this execution onto its children. This element is only meaningful to parent POMs.

整体管理可以受到pluginManagement的影响:

Plugin Management contains plugin elements in much the same way, except that rather than configuring plugin information for this particular project build, it is intended to configure project builds that inherit from this one. However, this only configures plugins that are actually referenced within the plugins element in the children. The children have every right to override pluginManagement definitions.

因此,在 pom 层次结构的某个点的插件定义可能对最终有效构建没有意义。