checkstyle.xml
看起来像
<property name="severity" value="warning"/>
<property name="fileExtensions" value="java, properties, xml"/>
<module name="TreeWalker">
<property name="tabWidth" value="4"/>
<module name="JavadocMethod">
<property name="scope" value="public"/>
<property name="allowMissingParamTags" value="true"/>
<property name="allowMissingThrowsTags" value="true"/>
<property name="allowMissingReturnTag" value="true"/>
<property name="minLineCount" value="2"/>
<property name="allowedAnnotations" value="Override, Test"/>
<property name="allowThrowsTagsForSubclasses" value="true"/>
</module>
<module name="JavadocVariable">
<property name="scope" value="protected"/>
</module>
<module name="AvoidStarImport"/>
</module>
pom.xml
看起来像
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>my-group</groupId>
<artifactId>my-tests</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>my-tests</name>
<description>my-tests</description>
<properties>
<checkstyle.config.location>checkstyle.xml</checkstyle.config.location>
</properties>
<profiles>
<profile>
<id>checkstyle-profile</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.17</version>
<configuration>
<configLocation>checkstyle.xml</configLocation>
</configuration>
<executions>
<execution>
<id>checkstyle-check</id>
<goals>
<goal>check</goal>
</goals>
<phase>test</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8.8</version>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.3.1</version>
</dependency>
</dependencies>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.17</version>
<configuration>
<configLocation>checkstyle.xml</configLocation>
</configuration>
<reportSets>
<reportSet>
<reports>
<report>checkstyle</report>
</reports>
</reportSet>
</reportSets>
</plugin>
</plugins>
</reporting>
</project>
如果我在Eclipse中运行Checkstyle,它会显示错误。但是在命令行上,不会生成Checkstyle报告。我该如何解决这个问题?
答案 0 :(得分:0)
默认情况下,Maven Checkstyle插件仅报告error
级别的违规行为。在您的checkstyle.xml
中,您已声明所有检查都会报告warning
级别的问题,以及您没有看到任何输出的原因。
您可以在error
中向checkstyle.xml
声明severity所有支票:
<property name="severity" value="warning"/>
或更改pom.xml
中的violationSeverity:
<configuration>
<violationSeverity>warning</violationSeverity>
<configLocation>checkstyle.xml</configLocation>
</configuration>