Friday, October 23, 2015

Maven phases and goals

Maven has a life cycle in its build process. The key concept is "Phase". Do not be confused by another concept "goal". There are different but related. For example, "package" is a phase. It is not a goal.

Maven can support a number of different life cycles. But the mostly used one is the default Maven life cycle.

The default life cycle has the following phases (For a more detailed description, see reference[1]). And they are stepped through in order until it reaches at the phase that is specified in the Maven command.

  1. process-resources
  2. compile
  3. process-classes
  4. process-test-resources
  5. test-compile
  6. test
  7. prepare-package
  8. package
  9. install

Maven delegates the work to Maven plugins.

Plugin goals can be attached to a life cycle phase. When Maven moves through the phases, it executes the goals attached to each phase. Each phase can have zero or more goals bound to it.

A phase may mean different things to different projects. For example, for the package phase, a JAR project will produce a JAR file, while a web application will produce a WAR file.

If no plugin is specified in the pom file, Maven seems to use its default plugins. See reference[2].

You can run Maven by specifying a phase as in "mvn install". You can also run Maven by specifying the actual goals as in "mvn resources:resources compiler:compile".

References

[1] https://maven.apache.org/ref/3.3.3/maven-core/lifecycles.html
[2] https://maven.apache.org/ref/3.3.3/maven-core/default-bindings.html

No comments:

Post a Comment