15

在父 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. <execution>是否可以在子项目中禁用某些功能,例如只运行execution 3和跳过 1 和 2?
  2. 是否可以完全覆盖子项目中的执行,例如,我的exection 4子项目中有一个,我只想运行这个execution并且永远不会在父 POM 中运行执行 1、2、3。
4

1 回答 1

24

一个快速的选项是<phase>none</phase>在覆盖每个执行时使用。因此,例如仅运行执行 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

于 2013-07-03T08:18:40.300 回答