0

我尝试将自定义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>会被忽略,以及如何修复它?

4

2 回答 2

1

您好@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>
于 2020-11-01T14:45:50.907 回答
0

一个解决方案是使用 config location 参数启动 maven 任务:

mvn checkstyle:check -Dcheckstyle.config.location=checkstyle.xml
于 2020-11-02T22:39:26.130 回答