0

I'm working on a Project which uses the same Plugin Multiple Times in multiple Parent Pom Files. Normally, if you use two Plugins in the same maven phase, it will execute the plugin which is first defined in the POM. In my case Maven merges the Plugins which causes my Plugins to be executed in the wrong order.

I want my Plugins to be executed in the following Order:

first,second,third,fourth

But the order it executes them is:

first,second,fourth,third

These are my POM's:

ParentParentPom.xml

<plugins>
   <plugin>
      <groupId>com.google.code.maven-replacer-plugin</groupId>
      <artifactId>replacer</artifactId>
      <version>1.5.3</version>
      <configuration></configuration>
      <executions>
         <execution>
            <id>first-plugin-execution</id>
            <phase>prepare-package</phase>
            <goals>
               <goal>replace</goal>
            </goals>
         </execution>
      </executions>
   </plugin>
   <plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>exec-maven-plugin</artifactId>
      <version>3.0.0</version>
      <executions>
         <execution>
            <id>second-plugin-execution</id>
            <phase>generate-sources</phase>
            <goals>
               <goal>java</goal>
            </goals>
         </execution>
      </executions>
   </plugin>
</plugins>

ParentPom.xml

<plugins>
   <plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>exec-maven-plugin</artifactId>
      <version>3.0.0</version>
      <executions>
         <execution>
            <id>third-plugin-execution</id>
            <phase>compile</phase>
            <goals>
               <goal>java</goal>
            </goals>
         </execution>
      </executions>
   </plugin>
   <plugin>
      <groupId>com.google.code.maven-replacer-plugin</groupId>
      <artifactId>replacer</artifactId>
      <version>1.5.3</version>
      <configuration></configuration>
      <executions>
         <execution>
            <id>fourth-plugin-execution</id>
            <phase>compile</phase>
            <goals>
               <goal>replace
            </goal>
            </goals>
         </execution>
      </executions>
   </plugin>
</plugins>

Effective Pom.xml

I looked into the Effective Pom of my Project and saw that Maven merged the plugins like this:

<plugins>
   <plugin>
      <groupId>com.google.code.maven-replacer-plugin</groupId>
      <artifactId>replacer</artifactId>
      <version>1.5.3</version>
      <executions>
         <execution>
            <id>first-plugin-execution</id>
            <phase>prepare-package</phase>
            <goals>
               <goal>replace</goal>
            </goals>
         </execution>
         <execution>
            <id>fourth-plugin-execution</id>
            <phase>compile</phase>
            <goals>
               <goal>replace</goal>
            </goals>
         </execution>
      </executions>
   </plugin>
   <plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>exec-maven-plugin</artifactId>
      <version>3.0.0</version>
      <executions>
         <execution>
            <id>second-plugin-execution</id>
            <phase>generate-sources</phase>
            <goals>
               <goal>java</goal>
            </goals>
         </execution>
         <execution>
            <id>third-plugin-execution</id>
            <phase>compile</phase>
            <goals>
               <goal>java</goal>
            </goals>
         </execution>
      </executions>
   </plugin>
</plugins>

Changing the Phases of the Plugins is not an option because these plugins rely on plugins which are executed in the compile phase and other plugins rely on the execution of the thrith and fourth execution too.

Is there any way I can prevent maven from merging these plugins together, so that they stay in the right order?

Beanssss
  • 65
  • 5
  • 1
    The clean solution is to change the phases. Why can't you do that? – J Fabian Meier Jan 24 '22 at 15:39
  • i have multiple plugins which rely on these plugins, they have to be executed in the compile phase. And i cant execute them before, becuase the exec-maven-plugin relys on plugins which are executed in the compile phase too. – Beanssss Jan 24 '22 at 15:42
  • If changing the phases of the plugin executions isn't an option, you might be out of luck. Please see [this answer](https://stackoverflow.com/a/55858093/944849) to get ideas for how you could do this by introducing another phase. – user944849 Jan 24 '22 at 16:31
  • There are actually a lot of phases. Carefully distributing your plugin executions to different phases might solve your problem. You could e.g. try move all the "later" plugins to process-classes, and the "earlier" ones to e.g. process-resources – J Fabian Meier Jan 24 '22 at 16:40

0 Answers0