我想在运行 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 插件之前打印了两条消息。如何强制在 runig 插件之前打印第一个 mesege,然后在它之后打印第二个。
将插件放入不同的生命周期阶段。其他一切都很脆弱。