Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When plugin goal is executed: before or after declared phase?

I have a question about maven pom. I have this pom.xml

<plugins>
<plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>run</goal>
            </goals>
            <configuration>
                <tasks>
                    <echo>Hello world!</echo>
                </tasks>
            </configuration>
        </execution>
    </executions>
</plugin>
</plugins>

when the goal run is executed? Before or after package phase?

(for Maven lifecycle see Maven lifecycle)

like image 297
Enrico Avatar asked Mar 21 '23 14:03

Enrico


2 Answers

Plugin goal is execute after beginning of declared phase (package), and before beginning of next phase (pre-integration-test).

In this scenerio maven command

mvn package

should print Hello World

Multiple executions in one phase:

Note: In Maven 2.0.5 and above, multiple goals bound to a phase are executed in the same order as they are declared in the POM, however multiple instances of the same plugin are not supported. Multiple instances of the same plugin are grouped to execute together and ordered in Maven 2.0.11 and above).

and

When multiple executions are given that match a particular phase, they are executed in the order specified in the POM, with inherited executions running first.

Source: Introduction to the Build Lifecycle

like image 179
MariuszS Avatar answered Apr 09 '23 21:04

MariuszS


In the case you have given it will be executed in the package phase, cause you explicit defined it to be executed during the package phase. If you like to get it executed before the package phase you need to use the prepare-package phase instead package.

like image 43
khmarbaise Avatar answered Apr 09 '23 22:04

khmarbaise