maven 究竟如何为相同的执行 ID 创建有效的插件配置?

How does exactly maven creates effective plugin configuration for the same execution ids?

我的项目中有如下插件配置:

        <plugin>
            <groupId>net.revelc.code</groupId>
            <artifactId>impsort-maven-plugin</artifactId>
            <version>1.4.0</version>
            <configuration>
                <includes>
                    <include>AA</include>
                </includes>
            </configuration>
            <executions>
                <execution>
                    <id>the_same_id</id>
                    <phase>process-test-classes</phase>
                    <goals>
                        <goal>check</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

以及我的父 pom 中的以下插件配置:

        <plugin>
            <groupId>net.revelc.code</groupId>
            <artifactId>impsort-maven-plugin</artifactId>
            <version>1.5.0</version>
            <configuration>
                <lineEnding>LF</lineEnding>
                <includes>
                    <include>A</include>
                    <include>B</include>
                    <include>C</include>
                </includes>
            </configuration>
            <executions>
                <execution>
                    <id>the_same_id</id>
                    <phase>process-sources</phase>
                    <goals>
                        <goal>sort</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

当我 运行 mvn help:effecive:pom 这是我插件的合并配置:

<plugins>
  <plugin>
    <groupId>net.revelc.code</groupId>
    <artifactId>impsort-maven-plugin</artifactId>
    <version>1.4.0</version>
    <executions>
      <execution>
        <id>the_same_id</id>
        <phase>process-test-classes</phase>
        <goals>
          <goal>check</goal>
          <goal>sort</goal>
        </goals>
        <configuration>
          <includes>
            <include>AA</include>
          </includes>
          <lineEnding>LF</lineEnding>
        </configuration>
      </execution>
    </executions>
    <configuration>
      <includes>
        <include>AA</include>
      </includes>
      <lineEnding>LF</lineEnding>
    </configuration>
  </plugin>

根据this插件配置的默认合并行为:

is to merge the content of the configuration element according to element name.

显示在 includes 部分,因为它只包含来自项目 pom 的内容,而不包含来自父 pom 的内容。但是按照这个逻辑我不明白为什么 effective-pom 配置包含两个目标而不是项目配置中的一个目标。

编辑: 正确记录在 POM reference, plugins section. Thanks Karl 中以指出这一点!

the codebase responsible for merging中,每个属性都略有不同。

如果你的目标没有被排除,那么these will be merged together

此外,考虑到 the plugin's lifecycle configuration,您的配置可能会以不同方式合并。