I have a project with subprojects where some have the Java plugin applied and some have the Android Plugin applied.
My checkstyle configuration looks like this:
subprojects {
plugins.apply('checkstyle')
checkstyle {
toolVersion = '6.13'
}
task checkstyle(type: Checkstyle) {
configFile rootProject.file('code_quality_tools/checkstyle.xml')
ignoreFailures false
showViolations true
source 'src'
include '**/*.java'
classpath = files()
}
}
When I execute ./gradlew clean checkstyle
everything works as planned and I do get the checkstyle reports.
However the moment I execute ./gradlew clean build
I get this error:
Caused by: : Unable to create a Checker: configLocation {<project_path>/<java_module>/config/checkstyle/checkstyle.xml}, classpath {<project_path>/<java_module>/build/classes/main:<project_path><java_module>/build/resources/main}.
at com.puppycrawl.tools.checkstyle.ant.CheckstyleAntTask.createChecker(CheckstyleAntTask.java:416)
at com.puppycrawl.tools.checkstyle.ant.CheckstyleAntTask.realExecute(CheckstyleAntTask.java:320)
at com.puppycrawl.tools.checkstyle.ant.CheckstyleAntTask.execute(CheckstyleAntTask.java:303)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.gradle.api.internal.project.ant.BasicAntBuilder.nodeCompleted(BasicAntBuilder.java:78)
at org.gradle.api.internal.project.antbuilder.AntBuilderDelegate.nodeCompleted(AntBuilderDelegate.groovy:80)
at org.gradle.api.plugins.quality.Checkstyle$_run_closure1.doCall(Checkstyle.groovy:146)
at org.gradle.api.internal.ClosureBackedAction.execute(ClosureBackedAction.java:67)
at org.gradle.util.ConfigureUtil.configure(ConfigureUtil.java:130)
at org.gradle.util.ConfigureUtil.configure(ConfigureUtil.java:91)
at org.gradle.api.internal.project.antbuilder.DefaultIsolatedAntBuilder$3.execute(DefaultIsolatedAntBuilder.java:178)
at org.gradle.api.internal.project.antbuilder.DefaultIsolatedAntBuilder$3.execute(DefaultIsolatedAntBuilder.java:160)
at org.gradle.api.internal.project.antbuilder.ClassPathToClassLoaderCache.withCachedClassLoader(ClassPathToClassLoaderCache.java:139)
at org.gradle.api.internal.project.antbuilder.DefaultIsolatedAntBuilder.execute(DefaultIsolatedAntBuilder.java:154)
at org.gradle.api.internal.project.IsolatedAntBuilder$execute$0.call(Unknown Source)
at org.gradle.api.plugins.quality.Checkstyle.run(Checkstyle.groovy:139)
at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:75)
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.doExecute(AnnotationProcessingTaskFactory.java:227)
The Java Module is trying to default back to the default configFile location even though I did specify it.
The moment I add the Checkstyle configuration file to <project_path>/<java_module>/config/checkstyle/checkstyle.xml
, ./gradlew clean build
does work.
I’ve tested this with Gradle versions: 2.8, 2.9 and 2.10-rc-1 and none of them do work.