[Total: 2    Average: 5/5]

Working with Maven as a build management tool, you’ve grown accustomed to its core plugins and abilities. Now, it’s time to up your Maven game and discover the top plugins that add time-saving functionality to your favorite build tool.

If you’re a Java developer, you’re probably familiar with Maven, a leading build tool that has been serving Java developers since 2014. A robust and flexible solution, Maven lets developers set standards for the software build process by (among others) mapping the objects and dependencies in a project, deploying it as an application, and making it accessible to other projects.

At its heart, Maven is a plugin execution framework, and can’t really do much without plugins to enable different categories of functionality. Before we discuss the useful Maven plugins we collected for you, let’s quickly review what it is Maven plugins do exactly and how they fit in the Maven build process.

The Abridged Anatomy of a Maven Build Process

When executed, Maven runs a series of tasks called goals, that are essentially Java methods. Contained within plugins, these goals perform various build tasks like compiling the project and running unit tests and creating JAR and WAR files. The two types of plugins include build plugins and reporting plugins, each defined in its respective element in the POM.

The order in which these tasks are executed is defined by Maven lifecycle phases across different lifecycles (default, clean and site lifecycles are pre-defined in Maven upon installation). Logically, different goals from different plugins are mapped to each phase. 

Since Maven comes pre-packaged with its own default core plugins, little to no configuration is needed to start using Maven as a build tool. Most experienced Java developers using it are well familiar with the pre-packaged plugins from the Apache Foundation as they are automatically downloaded and installed when you set up Maven.

Also, they tend to be the industry standard with convention taking precedence over personalization in most cases. That said, there’s a good reason there are hundreds of plugins out there, developed and curated by Apache (and others). These plugins can perform unique tasks, such as integrating with 3rd party tools for unit test reporting. Using readily available plugins to perform desired tasks can save you the effort of heavily customizing core plugins or even worse – writing your own

Based on community feedback and our own experience developing Java applications, we collected a number of Maven plugins pros keep in their Maven arsenal, and that can help you optimize your build process to save precious time.

8 Essential Maven Plugins for Java Developers

1. build-helper-maven-plugin

Supported in Maven 3+ (but with an older version for those of you out there still using Maven 2+), Build Helper is a multitool plugin includes a number of goals to enable some very useful capabilities in Maven. Among them are goals like resolving the latest released version of this project, adding test source directories to the POM, attaching additional artifacts to be installed and deployed, and more.

2. maven-jetty-plugin

The Jetty Maven plugin, developed by the Eclipse Foundation, lets you quickly deploy and test your Java webapp without having to create a WAR and deploy it to a web container. Once you’ve added jetty to the build section of your POM, you’ll be able to use your IDE to make changes to the project, and the Jetty Plugin will automatically reload the modified classes and web sources when you make changes to them. This allows for a more productive and speedy development cycle.

3. maven-shade-plugin

With this plugin by the Apache Foundation you can package the artifact in an uber-jar, including its dependencies and to shade the packages of some of the dependencies. Shading, in this context, refers to renaming the packages of some of the dependencies. This provides a clear advantage over your default JARing or WARing of artifacts as dependencies are taken into account.

4. spring-boot-maven-plugin

Spring Boot is frequently used to deploy the backend of a webapp, and this handy plugin adds Spring Boot support to Maven, so you can package executable JARs or WARs and run an application “in-place”. The plugin includes five goals for running, starting and stopping your Spring Boot application, repackaging your JAR/WAR to be executable, and a build-info goal to generate build information to be used by the Actuator.

5. sql-maven-plugin

Need to execute SQL commands in your build process? The Maven SQL plugin got you covered. You can execute SQL statements in a combination of strings with sqlCommand, a list of files with srcFiles and a set of files with fileset.

The last three plugins on our list perform a very similar task: packaging your Java application for easy execution on your operating system of choice.

6. Windows: launch4j-maven-plugin

Launch4j is a wrapper for JAR files, turning them into executable files to ease deployment of Java desktop applications. Launch4j can run on Windows, Linux, Solaris, or OS X and is configured through an XML file. The Maven plugin for Launch4j lets you generate the executable as part of the Maven build process.

7. Apple: appbundle-maven-plugin

Testing the app on an Apple machine? No problem. This Maven plugin creates an Application Bundle for OS X that will contain all your project dependencies and the necessary metadata.

8. Linux: debian-maven-plugin

Last but not least is this plugin for creating .deb package files, copyright file and transitively copying runtime dependencies. Cross platform and independent (does not require additional external tools), all you need in order to add it to your Maven build process is Java 8 and Maven 3.3.

This is, of course, a very short list. If you’re reading this and wondering “why isn’t X on the list”? Odds are it’s simply because our resident Maven experts have yet to come across it, and would be grateful if you make the introduction and mention your favorite Maven plugin (or plugins) in the comments.


Get Codota


About the author

Ilana is a content writer for the Codota.com blog