Maven插件执行顺序

时间:2016-04-18 16:18:27

标签: maven

我在订购Maven插件时遇到问题。 我想按声明顺序执行插件:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>test</groupId>
    <artifactId>test</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <id>task-1</id>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <phase>initialize</phase>
                        <configuration>
                            <target>
                            </target>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>task-2</id>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <phase>initialize</phase>
                    </execution>
                </executions>
                <configuration>
                    <executable>cmd</executable>
                    <arguments>
                        <argument>/c</argument>
                        <argument>rem</argument>
                    </arguments>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <id>task-3</id>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <phase>initialize</phase>
                        <configuration>
                            <target>
                            </target>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

我期望执行顺序:task-1,task-2,task-3

但执行mvn initialize后,实际的顺序是task-1,task-3,task-2:

[INFO] --- maven-antrun-plugin:1.3:run (task-1) @ test ---
[INFO] Executing tasks
[INFO] Executed tasks
[INFO]
[INFO] --- maven-antrun-plugin:1.3:run (task-3) @ test ---
[INFO] Executing tasks
[INFO] Executed tasks
[INFO]
[INFO] --- exec-maven-plugin:1.4.0:exec (task-2) @ test ---

我应该按照我想要的顺序更改插件?

1 个答案:

答案 0 :(得分:3)

我希望Maven警告一个重复的插件,即maven-antrun-plugin。 Maven不能有重复的插件,因此结果是task-3的执行块被合并到第一个maven-antrun-plugin中。 现在,Maven将遍历所有插件,自上而下并查找绑定到validate-phase的执行块。 这解释了结果。 在这种情况下是否有控制订单的选项?不,不在同一阶段。