Step by Step Guide to Developing a Custom Maven Plugin

Maven is a plugin execution framework where plugins do the heavy-lifting in the build process. This article demonstrates how to create a custom maven plugin and use it in a maven project

Somnath Musib
Nov 19, 2019 · 5 min read
Image for post
Image for post
Photo: Unsplash by Clint Patterson

Overview

Setting up the Maven Project

By convention, core Maven plugins provided by Maven are named as maven-<taskName>-plugin. Maven encourages custom plugins to be named as <taskName>-maven-plugin. Note that using maven-<taskName>-plugin pattern is an infringement of the Apache Maven Trademark

Image for post
Image for post
Creating a new Maven project
pom.xml file

Creating the MOJO

A mojo is an executable goal in Maven, and a plugin is a distribution of one or more related mojos

A maven plugin can consist of many mojos (goals). The execute method is the set of actions performed by a mojo

Executing Mojo

Image for post
Image for post
XmlToJsonMojo Javadoc
xmltojson-maven-plugin-demo pom.xml file

Conclusion

References

The Startup

Medium's largest active publication, followed by +730K people. Follow to join our community.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store