【问题标题】:Is it possible to override executions in maven pluginManagement?是否可以覆盖 maven pluginManagement 中的执行?
【发布时间】:2013-06-30 16:42:20
【问题描述】:

在父 POM 中,我有:

 <pluginManagement>
            <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.5</version>
                <executions>
                    <execution>
                       <id>execution 1</id>
                       ...
                    </execution>
                    <execution>
                       <id>execution 2</id>
                       ...
                    </execution>
                    <execution>
                       <id>execution 3</id>
                       ...
                    </execution>
                </executions>
            </plugin>
        <pluginManagement>

我的问题是:

  1. 是否可以在子项目中禁用某些&lt;execution&gt;,例如只运行execution 3并跳过1和2?
  2. 是否可以完全覆盖子项目中的执行,例如我的子项目中有一个exection 4 我只想运行这个execution,并且永远不会在父 POM 中运行执行 1,2,3。

【问题讨论】:

  • 使用每个项目的 POM 属性来激活配置文件的建议解决方案将不起作用,因为只能使用全局系统属性。

标签: maven


【解决方案1】:

一个快速的选择是在覆盖每个执行时使用&lt;phase&gt;none&lt;/phase&gt;。因此,例如要运行执行 3,您只需在 pom 中执行以下操作:

<build>
  <plugins>
    <plugin>
        <artifactId>maven-resources-plugin</artifactId>
        <version>2.5</version>
        <executions>
            <execution>
                <id>execution 1</id>
                <phase>none</phase>
                ...
            </execution>
            <execution>
                <id>execution 2</id>
                <phase>none</phase>
                ...
            </execution>
            <execution>
                <id>execution 3</id>
                ...
            </execution>
        </executions>
    </plugin>
    ...
  </plugins>
  ...
</build>

请注意,这不是官方记录的功能,因此可以随时删除对此的支持。

推荐的解决方案可能是定义 profiles ,其中定义了 activation 部分:

<profile>
  <id>execution3</id>
  <activation>
    <property>
      <name>maven.resources.plugin.execution3</name>
      <value>true</value>
    </property>
  </activation>
  ...

在您的子项目中,您只需设置所需的属性:

<properties>
    <maven.resources.plugin.execution3>true</maven.resources.plugin.execution3>
</properties>

可以在此处找到有关配置文件激活的更多详细信息: http://maven.apache.org/settings.html#Activation

【讨论】:

    猜你喜欢
    • 2011-06-07
    • 1970-01-01
    • 2020-08-19
    • 1970-01-01
    • 2022-11-23
    • 2012-05-16
    • 1970-01-01
    • 2011-04-06
    • 1970-01-01
    相关资源
    最近更新 更多