I have the following project structure:
project
checkstyle
checkstyle.xml
subproject1
...
subproject2
...
build.gradle
My configuration for checkstyle in the build.gradle
is as follows:
allprojects {
apply plugin: 'checkstyle'
checkstyle {
configFile = 'checkstyle/checkstyle.xml' as File
}
}
When I was using gradle 2.1, build worked OK. After upgrading to 2.2 or 2.2.1 the error occurs:
:subproject1:checkstyleMain FAILED
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':subproject1:checkstyleMain'.
> Unable to create a Checker: unable to find /home/my/project/subproject1/checkstyle/checkstyle.xml
Gradle is now looking for 'checkstyle/checkstyle.xml' in the subproject directory, which is not what I would expect.
I have found that they mentioned this change in 2.2 release notes. But they did not tell how to maintain old behavior of resolving that path. How to do this?
I tried using project.file
but it does not work too.
2.1. To use checkstyle in Gradle you have add the plug-in to your build. gradle and provide a config\checkstyle\checkstyle. xml checkstyle configuration file. A detailed example is given in the checkstyle with Gradle exercise.
The Checkstyle plugin performs quality checks on your project's Java source files using Checkstyle and generates reports from these checks.
in your snippet
allprojects {
apply plugin: 'checkstyle'
checkstyle {
configFile = 'checkstyle/checkstyle.xml' as File
}
}
you configure the configfile per project to be relative from the subproject you're currently configuring. you can fix this by replacing
checkstyle {
configFile = 'checkstyle/checkstyle.xml' as File
}
by
checkstyle {
configFile = rootProject.file('checkstyle/checkstyle.xml')
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With