如何设置Maven插件在同一阶段和从不同插件执行的顺序

6g8kf2rb  于 2023-04-11  发布在  Maven
关注(0)|答案(1)|浏览(156)

我想在运行maven插件之前和之后打印消息。
我试着这样做:

<plugins>
  <plugin>
    <groupId>com.soebes.maven.plugins</groupId>
    <artifactId>echo-maven-plugin</artifactId>
    <version>0.5.0</version>
    <executions>
      <execution>
        <id>echo-before-call-plugin</id>
        <phase>compile</phase>
        <goals>
          <goal>echo</goal>
        </goals>
        <configuration>
        <echos>
          <echo>Before run plugin antrun.</echo>
        </echos>
      </configuration>
    </execution>
  </plugin>

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <executions>
      <execution>
        <phase>compile</phase>
          <configuration>
            <tasks>
                    .....
            </tasks>
          </configuration>
          <goals>
            <goal>run</goal>
          </goals>
        </execution>
    </executions>
  </plugin>

  <plugin>
    <groupId>com.soebes.maven.plugins</groupId>
    <artifactId>echo-maven-plugin</artifactId>
    <version>0.5.0</version>
    <executions>
      <execution>
        <id>echo-before-call-plugin</id>
        <phase>compile</phase>
        <goals>
          <goal>echo</goal>
        </goals>
        <configuration>
        <echos>
          <echo>After run plugin antrun.</echo>
        </echos>
      </configuration>
    </execution>
  </plugin>
</plugins>

但是它得到一个错误-在 *.pom文件中我们只能使用一次插件。
接下来我试着这样做:

<plugins>
  <plugin>
    <groupId>com.soebes.maven.plugins</groupId>
    <artifactId>echo-maven-plugin</artifactId>
    <version>0.5.0</version>
    <executions>
      <execution>
        <id>echo-before-call-plugin</id>
        <phase>compile</phase>
        <goals>
          <goal>echo</goal>
        </goals>
        <configuration>
        <echos>
          <echo>Before run plugin antrun.</echo>
        </echos>
      </configuration>
    </execution>
    
     <execution>
        <id>echo-after-call-plugin</id>
        <phase>compile</phase>
        <goals>
          <goal>echo</goal>
        </goals>
        <configuration>
        <echos>
          <echo>After run plugin antrun.</echo>
        </echos>
      </configuration>
    </execution>
  </plugin>

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <executions>
      <execution>
        <phase>compile</phase>
          <configuration>
            <tasks>
                    .....
            </tasks>
          </configuration>
          <goals>
            <goal>run</goal>
          </goals>
        </execution>
    </executions>
  </plugin>
</plugins>

有没有错误,但这两个消息都是在运行前打印的antrun插件.如何强制打印第一个mesege前runig插件,和第二个后.

k97glaaz

k97glaaz1#

把插件放到不同的生命周期阶段,其他的都很脆弱。

相关问题