10 Important Maven plugins for Java Developers
By: Anish Antony
Tags: Web Development, Coding, Maven, Java, Programming

Plugins are widening the maven. Using different maven plugin it is able to do a lot of super cool stuff. In this article lets discuss some of the most frequently using maven plugins.

Photo by Anton Nazaretian on Unsplash

If you are a java developer then it is very sure that you should aware of Maven. Maven is one of the great tools for the build process. If you integrated your project with maven, then you don't need to worry about the build complexity because maven makes the build process so smooth.

In this article, we are discussing some advanced plugins in maven which you should bookmark.

build-helper-maven-plugin

The plugin is mainly for adding additional source or resource directories.

It is helpful if your project has an additional source directory other than the src folder. Using this plugin it is able to include more source directories as part of the build.

Below example explains it in more detail.

In the above pom.xml explains, it considers the additional source directory gen/src folder as part of the build.

maven-shade-plugin

Using the maven-shade-plugin, it is able to create the uber jar. The uber jar contains everything including the dependencies of the project. While executing, You don't need to add the dependent jars on the classpath. All the dependencies are included in the uber jar.

This plugin is so helpful for making executable single jars. Using the maven-shade-plugin configuration, it can able to mention what are the things to be included/excluded on the uber jar.

Below shows a small example using maven-shade-plugin.

The above pom.xml creates an uber jar by including the commons-lang3 dependency, also it is excluding the unwanted files inside the META-INF and other folders as based on the configuration.

sql-maven-plugin

The main use of sql-maven-plugin is used to execute the SQL statement as part of the build process. This plugin helps execute test cases with DB connection. With the help of this plugin, it is able to clean up the database, Run the init scripts, populate the database based on the environment.

spring-boot-maven-plugin

The spring-boot-maven-plugin is used for enabling the spring boot support on maven. Using this plugin it is able to control the artifact output. Such as it can repackage the artifact for jar or war, it can specify the main class explicitly via plugin, Able to specify custom layers for the application.

Below shows a pom.xml file with spring-boot-maven plugin. Here the layout of the artifact mentioned is war and the main class explicitly specified in the plugin. There are two output for the build, one is the original one and another one is the repackaged one using this plugin.

maven-deploy-plugin

This plugin is mainly used for handling the deployment. Using this plugin it is able to deploy the file to a remote repository or a local repository.

There are two main phases for this plugin. One is to deploy the artifact to a remote location using the deploy:deploy goal.

The second one is can upload the artifact into a remote maven repository using the deploy:deploy-file goal. For executing this goal, the user should need to pass the repo path, artifact file, group id, artifact id, version, and repo information.

maven-surefire-plugin

Maven-surefire-plugin helps to execute the test cases as part of the build. Also, the plugin will output the execution output as plain text or XML format.

The plugin supports the test execution tools such as JUnit, TestNG. The below image explains the maven surefire plugin report generation.

In the above image shows, the build executing two test cases, where one output success result and other one failed. The report shows the execution status of both test cases with the reason of failure.

maven-compiler-plugin

The plugin is used to compile the source. By applying this plugin on pom.xml it is able to compile the source with any java versions, which can be specified in the plugin itself.

Above shows an example of maven-compiler plugin , here it is mentioned the source and target as 1.8.

The source is 1.8 which means you can use the java 1.8 features in your source code.

The target is1.8 which means the compiled classes are compatible with java 1.8.

launch4j-maven-plugin

The plugin is used for making windows executable. You can create console based or GUI based installation tool by using launch4j.

Let's understand how to integrate the launch4j-maven-plugin with your swing application.

For that, I created a swing JFrame and build it as a jar file. Here is the launch4j integrated pom.xml file for the application

In the above launch4j plugin output two types of executable outputs. One is console output and another one is GUI output.

appbundle-maven-plugin

This plugin is used to create the application bundle for OS X. The bundle contains your project, its dependencies and the necessary metadata files. Also, it is possible to embedding java JDK with this bundle.

debian-maven-plugin

This plugin is used to build DEB packages for the maven project. This packaging can be used in the DEB based OS such as ubuntu and debian.