[英]Property does not exist error in checkstyle configuration file
我使用Android Studio创建了一个Android项目。 在app的build.gradle
中添加:
apply from: '../config/quality.gradle'
然后我用两个文件创建config
目录: quality.gradle
like:
apply plugin: 'checkstyle'
task checkstyle(type: Checkstyle) {
configFile file("${project.rootDir}/config/checkstyle.xml")
source 'src'
include '**/*.java'
exclude '**/gen/**'
classpath = files()
}
和checkstyle.xml
一样:
<?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>
运行gradle checkstyle
会出现以下错误:
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
如果我删除行:
<property name="allowSingleLineStatement" value="true"/>
有用。 但阅读文档 ,第一版也应该有效。
它发生的类似于:
<module name="EmptyCatchBlock">
<property name="exceptionVariableName" value="expected|ignore"/>
</module>
那扔我:
* What went wrong:
Execution failed for task ':app:checkstyle'.
> Unable to create a Checker: cannot initialize module TreeWalker - Unable to instantiate EmptyCatchBlock
我做错了什么或以什么方式错过理解文档?
在撰写本文时,Gradle默认使用Checkstyle 5.9 。 allowSingleLineStatement
属性仅在Checkstyle 6.5中添加 。 所以,你应该能够通过使用更新的Checkstyle版本来实现这一点:
checkstyle {
configFile = file("${project.rootDir}/config/checkstyle.xml")
toolVersion = '6.7'
}
不幸的是,Checkstyle文档没有版本化,所以网站总是只有最新的文档,这使得很难想象这样的东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.