Can I configure multiple plugin executions in pluginManagement, and choose from them in my child POM?

前端 未结 1 966
醉话见心
醉话见心 2021-02-01 02:28

I have 2 common plugin-driven tasks that I want to execute in my projects. Because they\'re common, I want to move their configuration to the pluginMangement sectio

相关标签:
1条回答
  • 2021-02-01 02:36

    You're correct, by default Maven will include all of the executions you have configured. Here's how I've dealt with that situation before.

    <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>
    

    Note, the executions are bound to phase none. In the child, you enable the parts that should execute like this:

    <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>
    

    If the child doesn't explicitly bind the execution to a phase, it won't run. This allows you to pick and choose the executions desired.

    0 讨论(0)
提交回复
热议问题