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

I have a project consisting of several Maven modules that are children of the parent module. I have a parent set to use checkstyle, and child modules inherit this behavior correctly. I would like all child modules to use the parental suppression file defined in its plugin. I define the checkstyle.suppression property that 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 is great for the parent, but all child modules try to find the file in basedir , which makes sense.
I'm sure there should be a simple solution that I am missing, but is there a way to determine this location so that all child modules use the parent location without hard coding?

+4
source share
4 answers

The answers above are dangerous. I argue that each project must be autonomous, so accessing files external to it will break the assembly sooner or later. Checkstyle can take the URL for the file, but that means you cannot build offline. The best approach is to pack your file (you can also add pmd.xml) in a jar, and then add this jar to the class path of the checkstyle (or pmd) plugin. I have an example here and much more about overriding the classpath plugin here

+11
source
+2
source

Have you tried defining a property like this in the parent pom, or overriding it in the children?

  <properties> <checkstyle.suppressions>${parent.project.basedir}\src\checkstyle\suppressions.xml</checkstyle.suppressions> </properties> 
0
source

If the parent will not run checkstyle, you can simply rewrite it to

 <properties> <checkstyle.suppressions>..\..\src\checkstyle\suppressions.xml</checkstyle.suppressions> </properties> 

Or something like that. Or you can put something in settings.xml to point everything to the system configuration directory.

While this may not be recommended, you can use the project or task to download or configure by placing a copy of the suppressions.xml file in the location indicated by the property in settings.xml, and then always referring to these places.

0
source

All Articles