Maven goals cheat sheet

java maven cheat-sheet

πŸ” 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.

CommandImplicit Phases (executed in order)
mvn compilevalidate β†’ compile
mvn testvalidate β†’ compile β†’ test
mvn packagevalidate β†’ compile β†’ test β†’ package
mvn installvalidate β†’ compile β†’ test β†’ package β†’ install
mvn deployvalidate β†’ compile β†’ test β†’ package β†’ install β†’ deploy
mvn verifyvalidate β†’ 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

CommandDescriptionExample Output
mvn help:effective-pomDisplays the full merged POM (parent + profiles + defaults).Useful to debug inheritance issues
mvn help:describe -Dcmd=compileShows which plugin and goal are bound to compile.Reveals compiler:compile mapping
mvn help:describe -Dplugin=compilerLists all available goals for a given plugin.compiler:compile, compiler:testCompile
mvn dependency:treeDisplays dependency hierarchy and conflicts.A:1.0 β†’ B:2.0 β†’ C:3.1
mvn -XRuns 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