你是对的,默认情况下 Maven 将包括你配置的所有执行。这是我以前处理这种情况的方法。
<pluginManagement>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>some-maven-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<id>first-execution</id>
<phase>none</phase>
<goals>
<goal>some-goal</goal>
</goals>
<configuration>
<!-- plugin config to share -->
</configuration>
</execution>
<execution>
<id>second-execution</id>
<phase>none</phase>
<goals>
<goal>other-goal</goal>
</goals>
<configuration>
<!-- plugin config to share -->
</configuration>
</execution>
</executions>
</plugin>
</pluginManagement>
请注意,执行绑定到 phase none
。在孩子中,您启用应该像这样执行的部分:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>some-maven-plugin</artifactId>
<executions>
<execution>
<id>first-execution</id> <!-- be sure to use ID from parent -->
<phase>prepare-package</phase> <!-- whatever phase is desired -->
</execution>
<!-- enable other executions here - or don't -->
</executions>
</plugin>
如果子进程没有显式地将执行绑定到某个阶段,它将不会运行。这允许您挑选和选择所需的执行。