【发布时间】:2012-02-17 00:09:57
【问题描述】:
尝试根据guidelines on the apache site 在 maven pom 中设置自定义 checkstyle 配置在非常简单的情况下不起作用。
我创建了一个项目MyProject,使用Maven推荐的目录布局(即src/main/java/、src/main/resources),单个文件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 在 previous stack overflow post 中概述的策略在属性中进行更改,但这会在迁移到多模块项目时导致问题,并且不同于'官方' apache maven checkstyle 说明。
【问题讨论】:
-
您的配置 xml 到底在哪里?
标签: maven checkstyle