Maven plugin executes multiple times during build

北战南征 提交于 2019-12-01 16:28:16

问题


I have a Maven project with multiple overlapping profiles. I want to display the active profiles at the beginning of every build. So I put the following into the pom.xml <build> section:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-help-plugin</artifactId>
    <version>2.1.1</version>
    <executions>
        <execution>
            <id>display-active-profiles-at-start-of-build</id>
            <phase>validate</phase>
            <goals>
                <goal>active-profiles</goal>
            </goals>
        </execution>
    </executions>
</plugin>

The problem is that the plugin executes multiple times during the build:

  1. At the beginning of the build (during the validate phase).
  2. When jar:jar executes.
  3. After source:jar / during pre-integration-test (?), when Jetty is being started.

Similar results when specifying <phase>initialize</phase>. Is there a way to get this to only run at the beginning of the build?


回答1:


The reason it executes several times, is because one of your plugins is executing another lifecycle as part of its mojo.

source:jar definitely does it, as specified by its documentation.

Invokes the execution of the lifecycle phase generate-sources prior to executing itself.

jar:jar usually does not, but it may be that you have another plugin that spins off another lifecycle.

In case of generation of source jar, you generally don't need another lifecycle, and plugin authors recognized this by implementing jar-no-fork mojo.

You may substitute it for default jar mojo, by following steps described here -> http://maven.apache.org/plugins/maven-source-plugin/usage.html



来源:https://stackoverflow.com/questions/8041610/maven-plugin-executes-multiple-times-during-build

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!