Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

maven eclipse checkstyle plugin

I have custom checkstyle checks file (called checks.xml), and I'm trying to use that same file in both maven and eclipse. It all works well, except for the SuppressionFilter.

In this checks.xml file, I have

<module name="SuppressionFilter">
    <property name="file" value="src/main/resources/checkstyle/checkstyle-suppressions.xml"/>    
</module>

This works when I run through maven. However, when I run through eclipse, I need to change the config to be

<module name="SuppressionFilter">
    <property name="file" value="${basedir}/src/main/resources/checkstyle/checkstyle-suppressions.xml"/>    
</module>

If I run with the ${basedir} property with maven though, I get the error that property ${basedir} has not been set.

Is there a way use this same configuration file in both maven and eclipse? I feel like there should be, but I'm just missing something on how to properly populate the suppression filter.

thanks, Jeff

like image 372
Jeff Storey Avatar asked Oct 20 '10 19:10

Jeff Storey


1 Answers

This is hell. Eclipse and Maven handle suppressions different and don't share variables. Derived from Rolf Engelhard

So in pom.xml:

<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-checkstyle-plugin</artifactId>
   <version>2.8</version>
   <configuration>
     <propertyExpansion>config_loc=${basedir}/src/main/checkstyle</propertyExpansion>
     <configLocation>${basedir}/src/main/checkstyle/checkstyle.xml</configLocation>
      <suppressionsLocation>${basedir}/src/main/checkstyle/suppressions.xml</suppressionsLocation>
     <includeTestSourceDirectory>true</includeTestSourceDirectory>
   </configuration>
   <executions>
     <execution>
       <phase>verify</phase>
       <goals>
         <goal>check</goal>
       </goals>
     </execution>
   </executions>
 </plugin>

Now in checkstyle.xml (${config_log} is an Eclipse specific thing, but by specifying it in the pom we make it available to maven as well):

<module name="SuppressionFilter">
  <property name="file" value="${config_loc}/suppressions.xml" />
</module>

And if you're using maven-site-plugin or any other plugins that also rely on CheckStyle don't forget to update those to have the config_loc property as well (or declare it global to the pom, though I wasn't able to get this to work properly).

like image 177
cfeduke Avatar answered Sep 18 '22 23:09

cfeduke