Maven更改了不同配置文件的插件顺序

kav*_*i77 12 java maven-plugin maven-3 maven

我有两个不同的pom.xml定义相同plugin(相同groupIdartifactId不同execution:-))的地方profiles.在executions以相同的定义phase,因此,为了通过从XML的顺序计算:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>echo</groupId>
    <artifactId>test</artifactId>
    <name>echo-test</name>
    <version>1.0.0</version>
    <packaging>pom</packaging>
    <profiles>
        <profile>
            <id>1st-profile</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>1st-antrun-echo</id>
                                <phase>test</phase>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                                <configuration>
                                    <tasks>
                                        <echo>1st antrun plugin</echo>
                                    </tasks>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>2nd-profile</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>com.soebes.maven.plugins</groupId>
                        <artifactId>maven-echo-plugin</artifactId>
                        <version>0.1</version>
                        <executions>
                            <execution>
                                <id>1st-soebes-echo</id>
                                <phase>test</phase>
                                <goals>
                                    <goal>echo</goal>
                                </goals>
                                <configuration>
                                    <echos>
                                        <echo>1st echo-plugin</echo>
                                    </echos>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>2nd-antrun-echo</id>
                                <phase>test</phase>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                                <configuration>
                                    <tasks>
                                        <echo>2nd antrun plugin</echo>
                                    </tasks>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>
Run Code Online (Sandbox Code Playgroud)

所有插件执行都在test阶段中定义,因此我希望以下顺序:

1st antrun plugin
1st echo-plugin
2nd antrun plugin
Run Code Online (Sandbox Code Playgroud)

但是,由于antrun-plugins合并,我得到这个输出:

1st echo-plugin    
1st antrun plugin    
2nd antrun plugin
Run Code Online (Sandbox Code Playgroud)

此命令解释了为什么会发生这种情况: mvn help:effective-pom

除了引入新阶段之外,还有其他解决方案可以保留订单吗?我们的项目非常大,这是一个非常简单的例子.

为什么maven的限制是将插件合并为多个执行的插件?

Gáb*_*ták 23

根据我的经验,这是Maven中最大的错误之一.如果您在不同的配置文件中为同一插件配置了多个配置,则该订单根本无法预测.我甚至观察到,在给定阶段我在项目B中有一些插件顺序,并且一旦一些相同的插件在父项目中获得配置(甚至在同一阶段),订单就被破坏了.

https://issues.apache.org/jira/browse/MNG-2258上有一个与此相关的明显错误的错误.

可能的解决方法

  • 如果可能的话,尝试将一些插件转移到前一阶段(准备测试用于某些插件并测试其余插件)
  • 尝试使用groovy-maven-plugin脚本替换多个插件的功能(非常方便使用ant集成,并且您可以访问脚本中的活动配置文件列表)
  • 编写自己的mojo并以正确的顺序调用插件(请参阅 https://github.com/TimMoore/mojo-executor)
  • 试试看吧.也许它符合您的需求,并且Maven提供了许多好东西

我不认为你现在还能做更多的事情.