1

I want to print messages before I run the maven plugin and after it.

I try something like that:

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

But it gets an error - in the *.pom file we can use the plugin only once.

Next I try like this:

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

There is no error but both messages are printed before runing the antrun plugin. How to force to print the first mesege before runig plugin, and second after it.

  • As i know there is no possibility to order plugin executions in the same phase – Jens Apr 09 '23 at 20:52
  • 1
    The cleanest way is to use different life cycle phases... otherwise the order of the plugins in the xml is relevant... That means the echo-maven-plugin is defined in the same phase as the antrun-plugin and defined before the antrun-plugin (ordered in the xml file) which means both execution of the echo-maven-plugin will be done before... the question is why do you need that? And why do you bind antrun plugin into compile phase? For What purpose? – khmarbaise Apr 09 '23 at 21:55
  • In my original problem, I had two plugins called in the same phase. The first plugin sets properties, the second one uses them for work. Sometimes that solution does not work properly, so I want to display the values of properties using echo-maven-plugin before and after the first plugin run. I want to use echo-maven-plugin temporarily as a debugger to inspect the values of properties, but I am unable to precisely control the order of calling them. Is it even possible? – Jacek Karwatka Apr 10 '23 at 15:05

1 Answers1

0

Put the plugins into different life cycle phases. Everything else is just brittle.

J Fabian Meier
  • 33,516
  • 10
  • 64
  • 142