Custom JaCoCo Gradle Plugin - exclude files in report

I’m new to Gradle and Groovy. I have something like this in my build.gradle file:

jacocoTestReport {
    afterEvaluate {
        classDirectories.setFrom(files(classDirectories.files.collect {
            fileTree(dir: it, exclude: ['aaa/bbb.*', 'ccc/ddd/*',])

Now, I need this in my custom plugin. But I’m not sure how to set these excludes to it. I have something like this:

project.afterEvaluate { p ->
    def reportTask = project.tasks.findByName('jacocoTestReport') as JacocoReport
    reportTask.classDirectories.setFrom(reportTask.classDirectories.files.) // Now what?

And I’m stuck here. Can you help me sort this out, please?

Meanwhile I solved it.

def ex = ['aaa/bbb/*','ccc/ddd.*','eee/fff/*']
def ft = reportTask.classDirectories.asFileTree.matching {
    ex.each {
        exclude it

I don’t know how it works, but it works. I think gradle somehow wraps it to AntlrTask since it’s an implementation of PatternFilterable.