Maven 丢失了 checkstyle 配置
Maven lost checkstyle config
我尝试将自定义 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>
解决方案是使用配置位置参数启动 Maven 任务:
mvn checkstyle:check -Dcheckstyle.config.location=checkstyle.xml
我尝试将自定义 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>
解决方案是使用配置位置参数启动 Maven 任务:
mvn checkstyle:check -Dcheckstyle.config.location=checkstyle.xml