I'm working with a gradle
Java project where another user has enabled the checkstyle
plugin. Unfortunately, this addition breaks our ability to build from the CLI (a'la gradle build
). For some reason, however, we are still able to build internally in IntelliJ (2021.2 Community Ed).
I'm building with gradle
version 4.10.2. Below is a snippet from my build.gradle
where we enable checkstyle
.
subprojects { project ->
apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'checkstyle'
...
checkstyle {
configFile rootProject.file('checkstyle.xml')
toolVersion '7.1.1'
}
...
I've checked the compatibility guide here. According to this, I should be able to use this version.
Unfortunately though, my build fails when I try to gradle build
with the following error:
> Task :cache:checkstyleMain FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':cache:checkstyleMain'.
> Unable to create a Checker: configLocation {<REDACTED>}, classpath {<REDACTED>}.
Within my checkstyle.xml
, I have the following structure:
<module name="Checker">
<module name="FileTabCharacter">
<property name="eachLine" value="true"/>
</module>
<module name="LineLength">
<property name="max" value="150"/>
<property name="ignorePattern" value="^package.*|^import.*|a href|href|http://|https://|ftp://"/>
</module>
<module name="TreeWalker">
...
The strange thing is that when I move the LineLength
block under TreeWalker
as the parent, the error goes away and checkstyle
appears to work fine from both CLI and IDE. I got the idea from this post, however this change in checkstyle
behavior should have been introduced into 8.24 and should not be required for the version I'm trying to use.
Any ideas why checkstyle
would be behaving this way?
CodePudding user response:
Where LineLength goes in check style file depends on the Checkstyle version. Checkstyle 8.24 and higher: directly under Checker; Checkstyle < 8.24: under TreeWalker.
As per build.gradle file, the checkstyle version used is 7.1.1
checkstyle {
configFile rootProject.file('checkstyle.xml')
toolVersion '7.1.1'
}