Tôi tạo một dự án Android bằng Android Studio. Trong build.gradle
của ứng dụng thêm:Thuộc tính không tồn tại lỗi trong tệp cấu hình kiểu séc
apply from: '../config/quality.gradle'
Sau đó, tôi tạo ra các dir config
với hai tập tin: quality.gradle
như:
apply plugin: 'checkstyle'
task checkstyle(type: Checkstyle) {
configFile file("${project.rootDir}/config/checkstyle.xml")
source 'src'
include '**/*.java'
exclude '**/gen/**'
classpath = files()
}
Và checkstyle.xml
như:
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
<module name="Checker">
<module name="TreeWalker">
<module name="NeedBraces">
<property name="tokens" value="LITERAL_CASE, LITERAL_DEFAULT"/>
<property name="allowSingleLineStatement" value="true"/>
</module>
</module>
</module>
Chạy gradle checkstyle
mang lại cho tôi lỗi sau:
Executing external task 'checkstyle'...
:app:checkstyle FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:checkstyle'.
> Unable to create a Checker: cannot initialize module TreeWalker - Property 'allowSingleLineStatement' in module NeedBraces does not exist, please check the documentation
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Nếu tôi loại bỏ dòng:
<property name="allowSingleLineStatement" value="true"/>
nó hoạt động. Nhưng đọc documentation, phiên bản đầu tiên cũng sẽ hoạt động.
Nó xảy ra tương tự với:
<module name="EmptyCatchBlock">
<property name="exceptionVariableName" value="expected|ignore"/>
</module>
mà ném tôi:
* What went wrong:
Execution failed for task ':app:checkstyle'.
> Unable to create a Checker: cannot initialize module TreeWalker - Unable to instantiate EmptyCatchBlock
Tôi đang làm gì sai hoặc bằng cách nào tôi missunderstanding các tài liệu?
Lưu ý rằng tôi phải đi trước đường dẫn 'configFile' bằng từ khóa' file', nhưng giải pháp đã hoạt động. Cảm ơn rất nhiều, Thomas. – Birei
Yup, 'configFile' là một 'Tập tin'; cập nhật câu trả lời của tôi cho phù hợp. Cảm ơn! –
đã thử giải pháp này, nhưng IDEA cho tôi biết rằng 'Lỗi: (12, 0) Gradle: Đã xảy ra sự cố khi đánh giá dự án ': app'. > Không thể tìm thấy phương thức toolVersion() cho đối số [6.7] trên dự án ': app'.' – pratt