Strange Checkstyle behavior when checkstyle.xml is copied by custom task

Hi,

I use a custom task to copy the checkstyle.xml file from a dependcy JAR into the config/checkstyle directory.

The checkstyle.xml is valid and when I remove the custom task from build.gradle and run checkstyleMain everything works as expected.

But with the custom task Checkstyle is behaving strange: The ImportControl module runs amok and classifies hundreds of imports as disallowed.

The same config file is processed fine when I pass it to checkstyle on the command line.

I think that the custom task is somehow messing with the Checkstyle Plugin config.

Here is the relevant build.gradle snippet:

 dependencies {
      checkstyle configurations.checkstyleDependency.dependencies
      checkstyleDependency group: 'com.xxx.yyy', name: 'yyy-commons', version: '0.0.3-SNAPSHOT'
 }
 
 configurations {
     checkstyleDependency
 }
 
 task extractCheckstyleDependency(type: Copy, dependsOn: configurations.checkstyleDependency) {
    from zipTree(configurations.checkstyleDependency[0]), {include "checkstyle/*"}
    into 'config/checkstyle'
    eachFile {
        f -> f.path = f.path.replaceFirst('checkstyle/', '')
    }
    includeEmptyDirs false
}

checkstyle {
    toolVersion = "8.7"   
    maxWarnings = 0
}

tasks.withType(Checkstyle) {
	dependsOn extractCheckstyleDependency
    reports {
        xml.enabled true    // needed by jenkins
        html.enabled true
    }
}

I’ve opened an issue on github.

Please let me know if there is anything I could improve on extractCheckstyleDependency or the way it’s embedded in the rest of the configuration.

There is a regression in gradle >= 4.4 that causes the behaviours (linked in the github ticket in my earlier comment).
In 4.3.1 and from 4.6 (tested with a nightly build) the above setup will work.