checkstyle配置文件中的属性不存在错误

Bir*_*rei 10 checkstyle gradle

我使用Android Studio创建了一个Android项目.在build.gradle应用程序添加:

apply from: '../config/quality.gradle'
Run Code Online (Sandbox Code Playgroud)

然后我config用两个文件创建目录:quality.gradle如:

apply plugin: 'checkstyle'

task checkstyle(type: Checkstyle) {
    configFile file("${project.rootDir}/config/checkstyle.xml")
    source 'src'
    include '**/*.java'
    exclude '**/gen/**'
    classpath = files()
}
Run Code Online (Sandbox Code Playgroud)

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>
Run Code Online (Sandbox Code Playgroud)

跑步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
Run Code Online (Sandbox Code Playgroud)

如果我删除行:

<property name="allowSingleLineStatement" value="true"/>
Run Code Online (Sandbox Code Playgroud)

有用.但阅读文档,第一版也应该有效.

它发生的类似于:

<module name="EmptyCatchBlock">
    <property name="exceptionVariableName" value="expected|ignore"/>
</module>
Run Code Online (Sandbox Code Playgroud)

那扔我:

* What went wrong:
Execution failed for task ':app:checkstyle'.
> Unable to create a Checker: cannot initialize module TreeWalker - Unable to instantiate EmptyCatchBlock
Run Code Online (Sandbox Code Playgroud)

我做错了什么或以什么方式错过理解文档?

bar*_*uin 18

在撰写本文时,Gradle 默认使用Checkstyle 5.9.该allowSingleLineStatement物业仅在Checkstyle 6.5中添加.所以,你应该能够通过使用更新的Checkstyle版本来实现这一点:

checkstyle {
    configFile = file("${project.rootDir}/config/checkstyle.xml")
    toolVersion = '6.7'
}
Run Code Online (Sandbox Code Playgroud)

不幸的是,Checkstyle文档没有版本化,所以网站总是只有最新的文档,这使得很难找出这样的东西.