maven eclipse checkstyle插件

Jef*_*rey 5 eclipse maven-2 checkstyle

我有自定义checkstyle检查文件(称为checks.xml),我正在尝试在maven和eclipse中使用相同的文件.这一切都运作良好,除了SuppressionFilter.

在这个checks.xml文件中,我有

<module name="SuppressionFilter">
    <property name="file" value="src/main/resources/checkstyle/checkstyle-suppressions.xml"/>    
</module>
Run Code Online (Sandbox Code Playgroud)

这在我通过maven运行时有效.但是,当我运行eclipse时,我需要更改配置

<module name="SuppressionFilter">
    <property name="file" value="${basedir}/src/main/resources/checkstyle/checkstyle-suppressions.xml"/>    
</module>
Run Code Online (Sandbox Code Playgroud)

如果我使用带有maven的$ {basedir}属性运行,我会收到错误,即属性$ {basedir}尚未设置.

有没有办法在maven和eclipse中使用相同的配置文件?我觉得应该有,但我只是缺少一些关于如何正确填充抑制滤波器的东西.

谢谢,杰夫

cfe*_*uke 7

这是地狱。Eclipse 和 Maven 处理抑制不同并且不共享变量。源自罗尔夫·恩格尔哈德

所以在 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>
Run Code Online (Sandbox Code Playgroud)

现在在 checkstyle.xml 中(${config_log} 是一个 Eclipse 特定的东西,但通过在 pom 中指定它,我们也使它可用于 maven):

<module name="SuppressionFilter">
  <property name="file" value="${config_loc}/suppressions.xml" />
</module>
Run Code Online (Sandbox Code Playgroud)

如果您正在使用maven-site-plugin或任何其他也依赖 CheckStyle 的插件,请不要忘记更新那些具有 config_loc 属性的插件(或将其声明为 pom 全局,尽管我无法使其正常工作) )。


jgo*_*ian 5

当然有一种方法可以在maven和eclipse中使用相同的配置文件,但它需要先进行一些设置.我写了一篇关于如何实现这一目标的博客文章,即使对于多模块maven项目也是如此.看:maven-checkstyle-and-eclipse