maven eclipse checkstyle plugin

我与影子孤独终老i 提交于 2019-12-01 05:53:13

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

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).

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

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

You could try defining ${basedir} as a property in your pom.
See the pom reference quick overview.

<property>
          <name>basedir</name>
          <value>${project.basedir}</value>
</property>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!