【问题标题】:Checkstyle config used by Maven and EclipseMaven 和 Eclipse 使用的 Checkstyle 配置
【发布时间】:2019-03-25 09:31:51
【问题描述】:

我尝试在 Maven 和 Eclipse 中使用相同的 Checkstyle 配置文件。模块 SuppressionCommentFilter 在 Eclipse 中按预期工作,但 Maven 报告 TreeWalker 不允许作为 SuppressionCommentFilter 的父级 如果我将它从 TreeWalker 移动到 Checker,错误就会消失,但 Checkstyle 不会处理忽略 cmets。我在 Eclipse 中使用 Checkstyle 8.12,但没有找到将 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 插件一起使用。

【问题讨论】:

标签: eclipse maven checkstyle


【解决方案1】:

我在 Eclipse 中使用 Checkstyle 8.12,但除了 6.18 和 Maven 之外,还没有找到其他方法

您必须覆盖 maven 中的依赖项才能引入更新版本的 Checkstyle。默认情况下,maven 插件将只使用 6.18,但它可以被新版本覆盖。

https://maven.apache.org/plugins/maven-checkstyle-plugin/examples/upgrading-checkstyle.html

【讨论】:

    【解决方案2】:

    您似乎已将 checkstyle 定义为依赖项而不是插件。

    使用Apache Maven Checkstyle 的指南,我能够将 checkstyle 用于我的个人项目。这是来自我的pom.xmlplugins 部分的sn-p:

    <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 上说:

    亲爱的读者,如果你像我一样在这里用谷歌搜索,解决方案是 将&lt;module name="SuppressionCommentFilter"/&gt; 移动到下方 TreeWalker 模块。

    我已经用你正在使用的版本尝试了这个修复,它不再给出错误了。

    【讨论】:

    • pom 和配置文件的一切工作正常。唯一的问题是 SuppressionCommentFilter 模块。
    • 感谢您的尝试,但您的回答并没有解决如何让 SuppressionCommentFilter 模块与 Maven 一起工作的问题,而它在 Eclipse 中工作得很好。
    猜你喜欢
    • 2016-08-31
    • 1970-01-01
    • 1970-01-01
    • 2011-04-28
    • 2012-03-14
    • 2013-11-10
    • 2021-02-14
    • 2012-01-11
    相关资源
    最近更新 更多