Plugin maven eclipse checkstyle

I have a custom checkstyle checks file (called checks.xml) and I'm trying to use the same file in both maven and eclipse. Everything works well except SuppressionFilter .

In this checks.xml 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 launch the eclipse, I need to change the configuration as

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

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

Can I use this configuration file in both maven and eclipse? I feel it should be, but I just missed something on how to properly fill out the suppression filter.

thanks jeff

+4
source share
4 answers

Of course, there is a way to use the same configuration file in both maven and eclipse, but this requires a little configuration. I wrote a blog post on how to achieve this even for a multi-module maven project. see maven-checkstyle-and-eclipse

+5
source

This is hell. Eclipses Eclipse and Maven are different from each other and do not 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 a special Eclipse thing, but by specifying it in pom we make it available also for maven):

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

And if you use maven-site-plugin or any other plugins that also rely on CheckStyle, be sure to update them to have the config_loc property (or declare it global for pom, although I couldn’t make it work properly).

+4
source

<propertyExpansion>basedir=${session.executionRootDirectory}</propertyExpansion> works for me, but only when added to a <plugin> node, not a <execution> !

project.basedir does not work in multi-module projects because it will point to the submodule folder instead of the root folder.

+1
source

You could try defining ${basedir} as a property in your pom.
See the pom help summary .

 <property> <name>basedir</name> <value>${project.basedir}</value> </property> 
-2
source

All Articles