试图根据guidelines on the apache site在maven pom中设置自定义checkstyle配置不能用于非常简单的情况。忽略Maven Checkstyle configLocation?
我创建了一个项目,MyProject的,使用Maven的建议(即的src/main/JAVA /,SRC /主/资源)的目录布局,单个文件MyClass.java:
package com.myproject;
public class MyClass {
public static void main(String[] args) {
System.out.println("This line is longer than 80 characters which returns an error in sun_checks.xml, however my_checks.xml allows for much longer lines and will not return a long line error.");
}
}
空CheckStyle的文件,my_checks.xml:
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.2//EN"
"http://www.puppycrawl.com/dtds/configuration_1_2.dtd">
<module name="Checker">
<property name="severity" value="warning"/>
<module name="TreeWalker">
</module>
</module>
和POM文件根据该指南中的规格:
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.myproject</groupId>
<artifactId>A_Project</artifactId>
<name>A Project</name>
<version>1.0.0</version>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.8</version>
<configuration>
<configLocation>my_checks.xml</configLocation>
</configuration>
</plugin>
</plugins>
</reporting>
</project>
运行'mvn -X checkstyle:checkstyle'将使用sun_checks.xml(默认值),而不是使用my_checks.xml文件中的配置,这可以通过生成的checkstyle错误和调试输出(例如, '[DEBUG] request.getConfigLocation()config/sun_checks.xml')。
我知道my_checks.xml是有效的,因为checkstyle.config.location可以使用在由CARBONI勾画的战略性质被改变,但是这将导致移动到多模块项目时的问题,并从不同'官方'apache maven checkstyle说明。
确切地说你的配置xml位于何处? – Corubba