我可以在pluginManagement中配置多个插件执行,并在我的子POM中选择它们吗?

bac*_*car 36 maven-3 maven

我有两个常见的插件驱动的任务,我想在我的项目中执行.因为它们很常见,我想将它们的配置移动到pluginMangement共享父POM 的部分.但是,两个任务虽然完全不同,但使用相同的插件.在我的一些项目中,我只想做两个任务中的一个(我并不总是希望运行插件的所有执行).

有没有办法在pluginManagement父pom 的部分中指定插件的多个不同执行,并在我的孩子pom中选择一个(并且只有一个)实际运行的执行?如果我配置2个执行pluginManagement,似乎两个执行都将运行.

注:我想这可能,也可能不会,是问题的一个重复的Maven2 -与pluginManagement和亲子关系的问题,但问题是近4 screenfuls长(TL; DR),一个简洁的重复可能是值得的.

use*_*849 48

你是对的,默认情况下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>
Run Code Online (Sandbox Code Playgroud)

注意,执行必然是阶段性的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>
Run Code Online (Sandbox Code Playgroud)

如果子进程未将执行显式绑定到某个阶段,则它将不会运行.这允许您选择所需的执行.