0

我正在开发一个在多个父 Pom 文件中多次使用相同插件的项目。通常,如果您在同一个 maven 阶段使用两个插件,它将执行首先在 POM 中定义的插件。在我的例子中,Maven 合并了导致我的插件以错误的顺序执行的插件。

我希望我的插件按以下顺序执行:

第一第二第三第四

但它执行它们的顺序是:

第一,第二,第四,第三

这些是我的POM:

父父Pom.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>

父Pom.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>

有效的 Pom.xml

我查看了我项目的 Effective Pom,发现 Maven 合并了这样的插件:

<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>

更改插件的阶段不是一个选项,因为这些插件依赖于在编译阶段执行的插件,而其他插件也依赖于第 thrith 和第 4 次执行的执行。

有什么办法可以阻止 maven 将这些插件合并在一起,以便它们保持正确的顺序?

4

0 回答 0