Maven POM Lint Plugin

This post introduces the Maven POM Lint plugin as a lightweight way to enforce cleaner `pom.xml` structure and conventions. It explains key goals, output behavior, and why small consistency checks improve maintainability.

Coveros Staff

January 22, 2014

I am a big fan of static analysis and formatting tools. I just like my code to be as clean as possible. At the very least, being clean makes the code easier to read and maintain. If I can find a tool that will make it easy for me to keep my code clean, I’ll use it.

Recently I found the Maven POM Lint plugin. It runs against your pom.xml file and applies a series of rules that amount to best practices on ordering, including optional fields, and eliminating duplication. It provides a way to keep your pom.xml file clean without much additional effort.

In the <build> section of our pom.xml file, we add:

<plugin>
  <groupId>com.lewisd</groupId>
  <artifactId>lint-maven-plugin</artifactId>
  <version>0.0.8</version>
</plugin>

The plugin provides two goals. The first is lint:list. It shows a list of the rules that the plugin will run against the pom.xml file. A short description for each rule is shown, but some of the descriptions are incomplete and don’t give much more information than the error message does. Still, being able to see the list of the rules that will be applied can be useful.

The more important goal is lint:check. It applies the rules and reports on any violations it finds. By default, the build will fail if there are any violations found. Any violations that are found are reported to the console and written out to an XML file (by default,  target/maven-lint-result.xml).

[INFO] ------------------------------------------------------------------------
[INFO] Building SampleMavenApp 0.0.3-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- lint-maven-plugin:0.0.8:check (default-cli) @ sample-maven ---
[INFO] Writing summary report
[INFO] [LINT] Completed with 3 violations
[INFO] [LINT] OSSDevelopersSectionRule: missing <developers/> section : 0:0 : C:\Users\Gene Gotimer\workspace\hangman\pom.xml
[INFO] [LINT] OSSInceptionYearRule: missing <inceptionYear/> information : 0:0 : C:\Users\Gene Gotimer\workspace\hangman\pom.xml
[INFO] [LINT] GAVOrder: Found 'name' but was expecting 'packaging' : 19:8 : C:\Users\Gene Gotimer\workspace\hangman\pom.xml
[INFO] Writing xml report
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------

The list of rules to apply can be explicitly defined if you some of them do not apply to your project.

It may not add much to your project, but it doesn’t take much to run and keep your POM file a little cleaner.

Coveros Staff

Coveros Staff

This post represents the collective insights of the Coveros team. Our staff consists of software experts who bring deep experience in secure agile development, DevOps, testing, and software quality. Over the past 20 years, Coveros has trained more than 30,000 professionals and worked with half of the Fortune 100 companies on mission-critical software development challenges. We draw on this extensive experience to share practical insights, proven strategies, and real-world solutions that help organizations build better software faster and more securely.