本文介绍了是否可以在Maven pluginManagement中覆盖执行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在父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.
  1. Is it possible to disable some <execution> in sub-projects, e.g, only run execution 3 and skip 1 and 2?
  2. Is it possible to totally override the executions in sub-projects, e.g. I have an exection 4 in my sub-projectsand I want only run this execution and never run execution 1,2,3 in parent POM.

推荐答案

一个快速的选择是在覆盖每次执行时使用<phase>none</phase>.因此,例如仅运行执行3,您将在pom中执行以下操作:

A quick option is to use <phase>none</phase> when overriding each execution. So for example to run execution 3 only you would do the following in your 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>

请注意,这不是正式记录的功能,因此可以随时删除对此功能的支持.

It should be noted that this is not an officially documented feature, so support for this could be removed at any time.

推荐的解决方案可能是定义定义了activation节的profiles:

The recommend solution would probably be to define profiles which have activation sections defined:

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

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

The in your sub project you would just set the required properties:

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

有关个人资料激活的更多详细信息,可以在这里找到: http://maven.apache.org/settings.html#Activation

More details on profile activation can be found here:http://maven.apache.org/settings.html#Activation

这篇关于是否可以在Maven pluginManagement中覆盖执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 22:46