我有一个 pom.xml
,我在其中定义了相同的 plugin
(相同的 groupId
和 artifactId
,不同的执行
:-) ) 在两个不同的配置文件
中。 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>
所有插件执行都在 test
阶段定义,因此我期望以下顺序:
1st antrun plugin
1st echo-plugin
2nd antrun plugin
但是,由于合并了 antrun-plugins
,我得到了这个输出:
1st echo-plugin
1st antrun plugin
2nd antrun plugin
这个命令解释了为什么会这样:mvn help:effective-pom
除了引入新阶段之外,是否还有其他解决方案来保留顺序?我们的项目非常大,这是一个非常简化的示例。
为什么maven限制将插件合并为一个多次执行?
最佳答案
根据我的经验,这是 Maven 中最大的错误之一。如果您在不同的配置文件中对同一个插件有多个配置,那么顺序就无法预测了。我什至观察到,我在给定阶段的项目 B 中有一些插件顺序,一旦一些相同的插件在父项目中获得配置(甚至不在同一阶段),顺序就被破坏了。
在 https://issues.apache.org/jira/browse/MNG-2258 处有一个与此相关的明显错误关闭的错误.
可能的解决方法
- 如果可能,尝试将一些插件转移到上一阶段 (准备测试用于一些插件并测试其余部分)
- 尝试 用一个替换多个插件的功能 groovy-maven-plugin 脚本(与 ant 集成非常方便,并且 您到达脚本中的 Activity 配置文件列表)
- 写下你的 拥有 mojo 并以正确的顺序调用插件(参见 https://github.com/TimMoore/mojo-executor )
- 尝试 gradle。也许它符合您的需求,并且它带有许多来自 Maven 的好东西
我认为您现在无能为力。
关于java - Maven改变不同配置文件的插件顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22150209/