gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 03:07:08 28 4
gpt4 key购买 nike

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

apply from: '../config/quality.gradle'

然后我创建了 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()
}

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"/>

有用。但阅读 documentation ,第一个版本也应该工作。

它发生类似于:
<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 uses Checkstyle 5.9默认情况下。 allowSingleLineStatement属性(property)只有added in Checkstyle 6.5 .因此,您应该能够通过使用更新的 Checkstyle 版本来实现这一点:

checkstyle {
configFile = file("${project.rootDir}/config/checkstyle.xml")
toolVersion = '6.7'
}

不幸的是,Checkstyle 文档没有版本化,所以网站总是只有最新的文档,这使得很难弄清楚这样的事情。

关于gradle - checkstyle 配置文件中的属性不存在错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31001013/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com