Chapter 10. The Build Lifecycle

Introduction

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 ...

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

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.