首页 > 解决方案 > Maven 丢失了 checkstyle 配置

问题描述

我尝试将自定义checkstyle.xml配置而不是标准连接sun_checks.xml这个项目

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-checkstyle-plugin</artifactId>
    <version>${checkstyle.version}</version>
    <configuration>
        <configLocation>src/main/resources/checkstyle.xml</configLocation>
    </configuration>
    <reportSets>
        <reportSet>
            <reports>
                <report>checkstyle</report>
            </reports>
        </reportSet>
    </reportSets>
</plugin>

但是mvn -B clean verify checkstyle:checkstyle得到输出sun_checks.xml

[INFO] There are 206 errors reported by Checkstyle 8.29 with sun_checks.xml ruleset.

为什么<configLocation>会被忽略,以及如何修复它?

标签: mavencheckstylemaven-checkstyle-plugin

解决方案


您好@Pavel 尝试在您的源代码之外使用 checkstyle.xml,并且还可以选择设置目标。它应该可以解决您的问题。

<properties>
    <checkstyle.configLocation>src/checkstyle/checkstyle.xml</checkstyle.configLocation>
    <checkstyle.suppressionsLocation>src/checkstyle/suppressions.xml</checkstyle.suppressionsLocation>
</properties>
             <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-checkstyle-plugin</artifactId>
                <version>${checkstyle.version}</version>
<!-- for java
                <dependencies>
                    <dependency>
                        <groupId>com.puppycrawl.tools</groupId>
                        <artifactId>checkstyle</artifactId>
                        <version>8.26</version>
                    </dependency>
                </dependencies>
-->
                <configuration>
                    <configLocation>${checkstyle.configLocation}</configLocation>
                    <suppressionsLocation>${checkstyle.suppressionsLocation}</suppressionsLocation>
                    <sourceDirectories>
                        <sourceDirectory>src/main/java</sourceDirectory>
                        <sourceDirectory>src/test/java</sourceDirectory>
                    </sourceDirectories>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>check</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

推荐阅读