What Do id, phase, and goals Mean in Maven Plugins?

In Maven, when defining a plugin execution inside <executions>, the elements id, phase, and goals determine when and how the plugin runs during the build lifecycle.

Let's break it down:


πŸ”Ή 1. <id> (Optional, But Useful)

βœ… Example:


<execution>
    <id>prepare-agent</id>  <!-- Just a name, used for reference -->
    <goals>
        <goal>prepare-agent</goal>
    </goals>
</execution>

⚠ If you remove <id>, Maven still runs the execution, but you can't reference it by name.


πŸ”Ή 2. <phase> (Defines When It Runs)

βœ… Example:


<execution>
    <id>report</id>
    <phase>verify</phase>  <!-- This runs AFTER tests are completed -->
    <goals>
        <goal>report</goal>
    </goals>
</execution>

πŸš€ Why use verify?

⚠ If <phase> is missing, Maven does NOT know when to run it!