我可以在pluginManagement中配置多个插件执行,然后在子POM中从中选择吗? [英] Can I configure multiple plugin executions in pluginManagement, and choose from them in my child POM?

查看:433
本文介绍了我可以在pluginManagement中配置多个插件执行,然后在子POM中从中选择吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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 section of a shared parent POM. However, both of the 2 tasks, whilst otherwise completely distinct, use the same plugin. In some of my projects I only want to do 1 of the 2 tasks (I don't always want to run all executions of the plugin).

是否有一种方法可以在父pom的pluginManagement部分中指定插件的多个不同执行,并在子pom中选择一个(也只有一个)要实际运行的执行?如果我在pluginManagement中配置2个执行,似乎两个执行都将运行.

Is there a way to specify multiple different executions of a plugin, within the pluginManagement section of a parent pom, and choose in my child pom one (and only one) of those executions to actually run? If I configure 2 executions in pluginManagement, it seems that both executions will run.

注意:我认为这可能是或不是问题

Note: I think this may, or may not, be a duplicate of question Maven2 - problem with pluginManagement and parent-child relationship, but as the question is nearly 4 screenfuls long (TL;DR), a succinct duplicate might be worthwhile.

推荐答案

您是正确的,默认情况下,Maven将包括您已配置的所有执行.这是我以前处理这种情况的方式.

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>

请注意,执行绑定到阶段none.在子级中,启用应执行的部分,如下所示:

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.

这篇关于我可以在pluginManagement中配置多个插件执行,然后在子POM中从中选择吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆