问题描述
我尝试将自定义checkstyle.xml
配置代替标准sun_checks.xml
与this project连接。
<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>
会被忽略,并且要修复它?
解决方法
您好@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>
,
一种解决方案是使用config location参数启动Maven任务:
mvn checkstyle:check -Dcheckstyle.config.location=checkstyle.xml