What makes a Maven project good to work with and easy to maintain? There are five types of Maven plugins that will simplify the development process and increase maintainability of a project.
Apache Maven is a build automation tool used primarily for Java projects. It has been around for a while, and it does not seem to be going anywhere anytime soon (whether some of you like it or not). Recently, it has been confirmed yet again, this time in ZeroTurnaround’s Java Tools and Technologies Landscape Report 2016 (see the Build Tools section).
The good thing about Maven is that you can do almost anything with it and its plugins. With such a great ecosystem of plugins, able to do nearly anything, one might wonder where to begin when setting up a new Maven project, or improving your old one.
I usually like to think of five main categories – or pillars – that we will be looking into in this post. Each category will have a set of example plugins that are meant to serve merely as a starting point.
In this post I will assume that you have some experience with build tools in general, and Maven in particular.
1. Technical Aspects
First of all, you would like to make sure that all the technical stuff is in place. You might want to automate the packaging, the checks if the project is running latest version of all artifacts, that all the dependencies are met, and that the unused dependencies are removed. You might even want to define your own rules for all the things that cause troubles, or just simply annoy you down the line, making the build fail if they are not met.
With all that automation in place you will be getting predictable results and nice packaging from the first day of the project.
Some of the plugins that should be mentioned here:
- Versions plugin does the versions management of artifacts in a project’s POM file
- Dependency plugin helps you analyzing dependencies, building dependency trees, showing unused dependencies, etc
- Assembly plugin helps you packaging all the dependencies, modules, site documentation, and other files into a single distributable archive
- Enforcer plugin lets you make your own rules! You can set up your build to break if some of your requirements are not met
2. Legal Aspects
With all the technical stuff out of the way, we might want to make sure that the legal side is taken care of as well.
Yes, I know, it might be less fun thinking about licenses than writing code, but it is still something that has to be done. You still have to release your code under some kind of license, and you will have to make sure that the third-party licenses do not violate your own licensing. So, why not leaving that job to a plugin?
The following plugin will manage the license of a maven project and its dependencies; it will also update file headers, download dependency licenses, check third-party licenses, etc.
- License plugin
3. Rapid Development
Now, back to coding. Or even better – to seeing the results of your hard work. Chances are that you will be needing some kind of web or application server for running your code, and you want to able to deploy to that server in no time. Yet another kind of plugins that will be helping you from the very first day of the project.
Some of the plugins that can be mentioned here:
- Apache Tomcat plugin
- Jetty plugin
- WildFly plugin
- …or any other deploy plugin, depending on your application
Every decent project must also be properly documented. However, this is something that developers might postpone until the end. Well, no more! These kind of plugins will help you to get started early, and will help you to produce some beautiful (maybe?) and maintainable docs.
You might even consider coupling these with some rules in the Enforcer plugin, but tread carefully as too many and too strict rules can, and usually do, backfire.
5. Testing and QA
By now, your code should be looking great, with all the right licenses and up and running in no time. So, how about squashing some [virtual] bugs? The list below might help you setting up a proper QA environment and fixing bugs before the come crawling to your production servers.
A video of a talk I gave about this topic at JavaZone in Oslo (in Norwegian).
This blog post was originally posted on: http://mehmandarov.com/five-pillars-of-a-good-maven-project/