Book Image

Mastering Apache Maven 3

Book Image

Mastering Apache Maven 3

Overview of this book

Table of Contents (16 chapters)
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Developing custom plugins


A greater part of this chapter is already spent on providing all the necessary background knowledge to start Maven custom plugin development. Under this section, let's see how to build your own Maven custom plugin from scratch. There are so many Maven plugins out there, and most of the time, you can find a plugin to do whatever you want. Let's start by defining a use case for our custom plugin. Say, you want to write a plugin to send an email to a given recipient once the build is completed.

Maven plain Old Java Object (MOJO) is at the heart of a Maven plugin. A Maven plugin is a collection of goals, and each goal is implemented via a MOJO. In other words, a Maven plugin is a collection of MOJOs. To create a custom plugin, proceed with the following steps:

  1. The first step in writing a custom plugin is to identify the goals of the plugin, and then represent (and implement) each of them with a MOJO. In our case, we have a single goal, that is, to send an email once the...