Maven2. Phases vs. Goals

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>

8 thoughts on “Maven2. Phases vs. Goals

  1. This article opens more questions that it answers.

    Where is the connection between the goal “run” and the “ant task (like copying files)”?

  2. 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’

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

  4. Aha–so the “goal” is actually the goal of the *plugin*, whereas the phase relates to the Maven lifecycle?

  5. 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?

Comments are closed.