I'm trying to configure Checkstyle in the project. I've added:
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()
}
to my root gradle file in allprojects
.
But when I run ./gradlew checkstyle
I get:
* 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}.
Even the file with rules is located in specified dir.
Problem was that it couldn't find rules file. So I changed:
configFile = rootProject.file('config/checkstyle/checkstyle.xml')
to:
configFile = file("${rootDir}/config/checkstyle/checkstyle.xml")
and now it pick up it correctly.