Maven 和 Eclipse 使用的 Checkstyle 配置
Checkstyle config used by Maven and Eclipse
我正在尝试对 Maven 和 Eclipse 使用相同的 Checkstyle 配置文件。模块 SuppressionCommentFilter 在 Eclipse 中按预期工作,但 Maven 报告
不允许将 TreeWalker 作为 SuppressionCommentFilter 的父级
如果我将它从 TreeWalker 移到 Checker,错误就会消失,但 Checkstyle 不会处理忽略注释。我将 Checkstyle 8.12 与 Eclipse 一起使用,但还没有找到将 6.18 与 Maven 一起使用的方法。由于此模块自 3.5 以来一直是 Checkstyle 的一部分,所以我不明白这是怎么回事。有什么建议吗?
<module name="Checker">
<property name="severity" value="warning" />
<module name="TreeWalker">
<property name="tabWidth" value="4" />
<module name="SuppressionCommentFilter" />
马克问这看起来像什么,所以这是那段代码。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>verify-style</id>
<phase>process-classes</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
pom 和 Checkstyle 配置文件除
外都正常工作
如果它是 Treewalker 的子项,我会从 Maven 插件中得到错误,而不是从 Eclipse 插件中得到错误,但是我只能让它与 Eclipse 插件一起工作。
看来您已将 checkstyle 定义为依赖项而不是插件。
使用 Apache Maven Checkstyle 中的指南,我能够将 checkstyle 用于我的个人项目。这是我的 pom.xml
:
的 plugins
部分的片段
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>verify-style</id>
<phase>process-classes</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<configuration>
<logViolationsToConsole>true</logViolationsToConsole>
<configLocation>yourcheckstylexmlhere.xml</configLocation>
</configuration>
</plugin>
Maskime 在 GitHub 上说:
Dear reader if you googled your way here, like I did, the solution is
to move the <module name="SuppressionCommentFilter"/>
under the
TreeWalker
module.
我已经在您使用的版本上尝试了此修复程序,并且不再出现错误。
I am using Checkstyle 8.12 with Eclipse, but have not found a way to use other than 6.18 with Maven
您必须覆盖 Maven 中的依赖项以引入更新版本的 Checkstyle。默认情况下,maven 插件将仅使用 6.18,但可以覆盖更新版本。
见https://maven.apache.org/plugins/maven-checkstyle-plugin/examples/upgrading-checkstyle.html
我正在尝试对 Maven 和 Eclipse 使用相同的 Checkstyle 配置文件。模块 SuppressionCommentFilter 在 Eclipse 中按预期工作,但 Maven 报告 不允许将 TreeWalker 作为 SuppressionCommentFilter 的父级 如果我将它从 TreeWalker 移到 Checker,错误就会消失,但 Checkstyle 不会处理忽略注释。我将 Checkstyle 8.12 与 Eclipse 一起使用,但还没有找到将 6.18 与 Maven 一起使用的方法。由于此模块自 3.5 以来一直是 Checkstyle 的一部分,所以我不明白这是怎么回事。有什么建议吗?
<module name="Checker">
<property name="severity" value="warning" />
<module name="TreeWalker">
<property name="tabWidth" value="4" />
<module name="SuppressionCommentFilter" />
马克问这看起来像什么,所以这是那段代码。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>verify-style</id>
<phase>process-classes</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
pom 和 Checkstyle 配置文件除
外都正常工作
如果它是 Treewalker 的子项,我会从 Maven 插件中得到错误,而不是从 Eclipse 插件中得到错误,但是我只能让它与 Eclipse 插件一起工作。
看来您已将 checkstyle 定义为依赖项而不是插件。
使用 Apache Maven Checkstyle 中的指南,我能够将 checkstyle 用于我的个人项目。这是我的 pom.xml
:
plugins
部分的片段
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>verify-style</id>
<phase>process-classes</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<configuration>
<logViolationsToConsole>true</logViolationsToConsole>
<configLocation>yourcheckstylexmlhere.xml</configLocation>
</configuration>
</plugin>
Maskime 在 GitHub 上说:
Dear reader if you googled your way here, like I did, the solution is to move the
<module name="SuppressionCommentFilter"/>
under theTreeWalker
module.
我已经在您使用的版本上尝试了此修复程序,并且不再出现错误。
I am using Checkstyle 8.12 with Eclipse, but have not found a way to use other than 6.18 with Maven
您必须覆盖 Maven 中的依赖项以引入更新版本的 Checkstyle。默认情况下,maven 插件将仅使用 6.18,但可以覆盖更新版本。
见https://maven.apache.org/plugins/maven-checkstyle-plugin/examples/upgrading-checkstyle.html