Java – Maven changes the order of plug-ins for different configuration files
I have a POM XML, I defined the same plug-in in two different configuration files (the same groupid and artifactid, different execution: -) Execution is defined in the same phase, so the order is calculated by the order of 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>
All plug-in execution is defined in the test phase, so I expect the following order:
1st antrun plugin 1st echo-plugin 2nd antrun plugin
However, since antrun plugins are merged, I get this output:
1st echo-plugin 1st antrun plugin 2nd antrun plugin
This command explains why this happens: MVN help: effective POM
In addition to introducing new phases, are there other solutions to maintain orders? Our project is really big. This is a very simple example
Why does Maven's restriction merge plug-ins into multiple executing plug-ins?
Solution
In my experience, this is one of the biggest bugs in Maven If you configure multiple configurations for the same plug-in in different configuration files, the command is unpredictable at all I even observed that I have some plug-in order in project B at a given stage. Once the same plug-in gets a configuration in a parent project (not even in the same stage), this command is destroyed
stay https://jira.codehaus.org/browse/MNG-2258 There is an obvious error closing the bug
Possible solutions
If possible, try to move some plug-ins to the previous stage (prepare to test some plug-ins and test the rest) > try to replace the function of multiple plug-ins with a groovy Maven plug-in script (it is very convenient to integrate with ants and you will reach the list of active configuration files in the script) write your own Mojo and call the plug-ins in the correct order (see https://github.com/TimMoore/mojo-executor )> give it a try Maybe it meets your needs. It brings a lot of good things from Maven
I don't think there's anything else to do now
