Skip to content
πŸ‡«πŸ‡· Lire en franΓ§ais

Maven goals cheat sheet

← Posts 2 min read

πŸ” Search Maven Goal


Understanding Goal Chains

When you run a Maven command like mvn package, Maven doesn’t only execute that goal, it runs every phase leading up to it, in sequence.

| Command | Implicit Phases (executed in order) | | ------------- | -------------------------------------------------------- | | mvn compile | validate β†’ compile | | mvn test | validate β†’ compile β†’ test | | mvn package | validate β†’ compile β†’ test β†’ package | | mvn install | validate β†’ compile β†’ test β†’ package β†’ install | | mvn deploy | validate β†’ compile β†’ test β†’ package β†’ install β†’ deploy | | mvn verify | validate β†’ compile β†’ test β†’ verify |

Each phase is bound by default to one or more plugin goals.
Example:
compile β†’ compiler:compile
package β†’ jar:jar or war:war (depending on packaging type).


Diagnostic & Helper Commands

| Command | Description | Example Output | | ------------------------------------- | ------------------------------------------------------------------- | ------------------------------------------ | | mvn help:effective-pom | Displays the full merged POM (parent + profiles + defaults). | Useful to debug inheritance issues | | mvn help:describe -Dcmd=compile | Shows which plugin and goal are bound to compile. | Reveals compiler:compile mapping | | mvn help:describe -Dplugin=compiler | Lists all available goals for a given plugin. | compiler:compile, compiler:testCompile | | mvn dependency:tree | Displays dependency hierarchy and conflicts. | A:1.0 β†’ B:2.0 β†’ C:3.1 | | mvn -X | Runs in debug mode, showing plugin binding and lifecycle execution. | Great for build troubleshooting |


Custom Goal Bindings

You can attach plugin goals to different phases in your pom.xml:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-antrun-plugin</artifactId>
  <executions>
    <execution>
      <phase>generate-sources</phase>
      <goals>
        <goal>run</goal>
      </goals>
    </execution>
  </executions>
</plugin>

References