Cố gắng đặt cấu hình kiểu tùy chỉnh trong maven pom theo guidelines on the apache site không hoạt động trong trường hợp rất đơn giản.Maven Checkstyle configLocation bị bỏ qua?
Tôi tạo ra một dự án, MyProject, sử dụng bố trí thư mục khuyến cáo của Maven (tức src/main/java /, src/main/nguồn lực), một tập tin MyClass.java duy nhất:
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.");
}
}
một sản phẩm nào checkstyle tập tin, 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>
và một tập tin pom theo thông số kỹ thuật trong hướng dẫn:
<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>
Chạy 'mvn -X checkstyle: checkstyle' đang sử dụng sun_checks.xml (mặc định) thay vì sử dụng cấu hình trong tệp my_checks.xml, có thể thấy bằng cả hai lỗi kiểu kết quả kiểm tra và đầu ra gỡ lỗi (ví dụ: '[DEBUG] request.getConfigLocation() config/sun_checks.xml').
Tôi biết my_checks.xml hợp lệ vì checkstyle.config.location có thể được thay đổi trong thuộc tính sử dụng chiến lược được Carboni nêu trong , nhưng điều này gây ra sự cố khi di chuyển sang các dự án nhiều mô-đun và khác với hướng dẫn checkstyle apache maven 'chính thức'.
Xml cấu hình của bạn nằm ở đâu? – Corubba