Chapter 10. The Build Lifecycle


Maven models projects as nouns that are described by a POM. The POM captures the identity of a project: What does a project contain? What type of packaging does a project need? Does the project have a parent? What are the dependencies? We’ve explored the idea of describing a project in the previous chapters, but we haven’t introduced the mechanism that allows Maven to act upon these objects. In Maven, the “verbs” are goals packaged in Maven plugins that are tied to phases in a build lifecycle. A Maven lifecycle consists of a sequence of named phases: prepare-resources, compile, package, and install, among others. There is a phase that captures compilation and a phase that captures packaging. There are pre- and postphases that can be used to register goals that must run prior to compilation, or tasks that must be run after a particular phase. When you tell Maven to build a project, you are telling Maven to step through a defined sequence of phases and to execute any goals that may have been registered with each phase.

A build lifecycle is an organized sequence of phases that exist to give order to a set of goals. Those goals are chosen and bound by the packaging type of the project being acted upon. There are three standard lifecycles in Maven: clean, default (sometimes called build), and site. In this chapter, you will learn how Maven ties goals to lifecycle phases and how the lifecycle can be customized. You will also learn about the default ...

Get Maven: The Definitive Guide now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.