What is the difference between phases and goals in maven?
I would like to explain the difference with an example:
Imagine you need an ant task (like copying files) and you want to do this task on every call of
mvn install
For this it is necessary to bind the goal ‘run’ from the maven-ant plugin to the phase ‘install’ of the maven lifecycle:
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>install</phase>
<configuration>
<tasks>
<copy file="fromfile" todir="todirectory" />
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
This article opens more questions that it answers.
Where is the connection between the goal “run” and the “ant task (like copying files)”?
Sorry, that I couldn’t clarify this for you.
I will try it again: maven has a lifecycle with one step (phase) which is called ‘install’.
Now we want that maven copies a file every time it comes to the step (phase) ‘install’.
For this we did the binding and now maven executes the ‘run’ goal of the antplugin every time it reaches the phase ‘install’
Thank you very much as you provide a very good and useful things in very short. It helped me lot while studing Maven plugin developement.
Thanks again !!!!!!!!!!!
Binod Suman
Bangalore, India
Aha–so the “goal” is actually the goal of the *plugin*, whereas the phase relates to the Maven lifecycle?
Thanks Brian, that is indeed the case.
I am new to Maven.. I am seeing some plugins which are configured without in this case in which build phase the goal will be called/executed?
* without phase tag (it didn’t show the tag)
install is the phase in maven. Run is the goal of the plug in.