【发布时间】:2018-09-13 16:04:18
【问题描述】:
我正在尝试在项目中配置 Checkstyle。我添加了:
apply plugin: 'checkstyle'
checkstyle {
// assign the latest checkstyle version explicitly
// default version is very old, likes 5.9
toolVersion = '8.6'
// checkstyle.xml copy from:
// https://raw.githubusercontent.com/checkstyle/checkstyle/checkstyle-8.6/src/main/resources/google_checks.xml
// the version should be as same as plugin version
configFile = rootProject.file('config/checkstyle/checkstyle.xml')
}
task Checkstyle(type: Checkstyle) {
source 'src/main/java'
include '**/*.java'
exclude '**/gen/**'
exclude '**/R.java'
exclude '**/BuildConfig.java'
// empty classpath
classpath = rootProject.files()
}
到 allprojects 中的我的根 gradle 文件。
但是当我运行./gradlew checkstyle
我明白了:
* What went wrong:
Execution failed for task ':app:Checkstyle'.
> Unable to create Root Module: config {/Users/user/Development/project/config/checkstyle/checkstyle.xml}, classpath {null}.
即使是带有规则的文件也位于指定的目录中。
【问题讨论】:
-
这可能是
classpath行,您应该删除它。但更好的是,组织您的代码,以便您的真实代码(您想要检查的)位于 SourceSet 中(例如main)。那么你根本不需要创建任务,因为 Checkstyle 插件已经为你创建了完美的任务。 -
删除类路径会产生不同的错误:> 没有为属性“类路径”指定值。
标签: android checkstyle