Gradle checkstyle importcontrol in multi-project build


I want to use the the gradle checkstyle plugin with a gradle multiproject setup. However when defining an import control file like this:

<module name="ImportControl">
   <property name="file" value="config/checkstyle/import-control.xml"/>

Then invoking gradle checkstyleMain looks for this file relative to where I invoke gradle, so in different locations when I invoke from the root project or a subproject. This is rather annoying. Is there a clean solution? It is a common problem. One solution would be a parameter to force checkstyle to be invoked always from the same folder (e.g. the root folder).



From what I remember, you can pass user-defined properties to the checkstyle task, which you can then reference from the checkstyle files.


checkstyleMain {
    configProperties = ['baseDir': "$rootDir"]

It’s plain to see in the docs, but I missed it nevertheless.