Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use a single checkstyle suppression file in Maven for all modules

I have a project that consists of several Maven modules which are all children of a parent module. I have the parent set up to use checkstyle and the child modules all inherit this behaviour correctly. I would like all the child modules to use the parents suppression file defined in its plugin. I define a property checkstyle.suppression which is used in the checkstyle plugin

<properties>
  <checkstyle.suppressions>${basedir}\src\checkstyle\suppressions.xml</checkstyle.suppressions>
</properties>

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-checkstyle-plugin</artifactId>
    <version>2.2</version>
    <configuration>
      <configLocation>config/sun_checks.xml</configLocation>
      <suppressionsLocation>${checkstyle.suppressions}</suppressionsLocation>
      <suppressionsFileExpression>${checkstyle.suppressions}</suppressionsFileExpression>
    </configuration>
  </plugin>
</plugins>

Which works fine for the parent but all the child modules try to find the file in their basedir which does make sense.
I am sure there must be a simple solution I am missing but is there a way to define this location so that all the child modules will use the parent location without hard coding it?

like image 240
Shawn Vader Avatar asked Sep 03 '09 15:09

Shawn Vader


2 Answers

The answers above are dangerous. I maintain that each project should be self contained, so referring to files external to it is going to break a build sooner or later. Checkstyle can take a url for the file but that means you can't build offline. A better approach is to package your file (can also add pmd.xml) into a jar and then add that jar to the classpath of the checkstyle (or pmd) plugin. I have an example of it here and more about overridding a plugin classpath here

like image 95
Brian Fox Avatar answered Nov 12 '22 20:11

Brian Fox


The plugin's documentation mentions a similar use case here: http://maven.apache.org/plugins/maven-checkstyle-plugin/examples/multi-module-config.html

like image 34
Kutzi Avatar answered Nov 12 '22 19:11

Kutzi