Introduction
As described in Chapter 2, Maven is actually a platform that executes plugins within a build life cycle, in order to perform the tasks necessary to build a project. Maven’s core APIs handle the “heavy lifting” associated with loading project definitions (POMs), resolving project dependencies, and organizing and running plugins. The actual functional tasks, or work, of the build process are executed by the set of plugins associated with the phases of a project’s build life-cycle. This makes Maven’s plugin framework extremely important as a means of not only building a project, but also extending a project’s build to incorporate new functionality, such as integration with external tools and systems.
With most projects, the plugins provided “out of the box” by Maven are enough to satisfy the needs of most build processes (see Appendix A for a list of default plugins used to build a typical project). Even if a project requires a special task to be performed, it is still likely that a plugin already exists to perform this task. Such supplemental plugins can be found at the Apache Maven project, the loosely affiliated CodeHaus Mojo project, or even at the Web sites of third-party tools offering Maven integration by way of their own plugins (for a list of some additional plugins available for use, refer to the Plugin Matrix. However, if your project requires tasks that have no corresponding plugin, it may be necessary to write a custom plugin to integrate these tasks into the build life cycle.
This chapter will focus on the task of writing custom plugins. It starts by describing fundamentals, including a review of plugin terminology and the basic mechanics of the the Maven plugin framework. From there, the chapter will cover the tools available to simplify the life of the plugin developer. Finally, it will discuss the various ways that a plugin can interact with the Maven build environment and explore some examples.