Checking root resources with Checkstyle and Maven

The Maven plug-in for Checkstyle allows to run Checkstyle on your project’s resources. However, options were specialized for a Maven structure. It means it was designed to work on source, resource and test directories. But nothing is built-in for root resources, like your pom.xml files.

I had submitted an enhancement request on Apache’s JIRA. At the time, I had even though about submitting a patch for it. Other things happened then and I somehow put this issue apart to focus on other priorities. Fortunately, Noémi Balassa posted a workaround yesterday. I tested it this evening and it works great. I though it might be useful to share it here.

Here is the sample configuration I used for the Maven Checkstyle plug-in.

		<!-- ... -->
		<!-- XML Files -->


				<!-- Process the pom.xml file too -->
				<testSourceDirectories />
				<includes>**/*.xml, **/*.xsd</includes>
				<excludes>**/target/**/*, **/*.properties</excludes>

It goes in the build section of your POM.

As you can see, we consider the project’s directory as a source one. We exclude the Maven’s target directory from the search. Resource and test directories are already searched in the source processing. So, no need to enable something specific for them.

It works well and it is not that much complicated.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s