Configure JaCoCo exclusions according to subprojects

The Gradle project structure: a root project with 2 subproject: sub1 and sub2.

Each subproject applies JaCoCo and configure its own exclusions, for example for project sub1:

        getClassDirectories().setFrom(classDirectories.files.collect {
            fileTree(dir: it, exclude: ['/sub1Exclusions/**'])
        })

The root project is creating a jacocoTestReport after a jacocoMerge was being done on the subprojects reports.

However, the exclusions of the subprojects are not respected by the root because the jacocoMerge only looks at the executionData.

I would like to configure the root’s jacocoTestReport to have a configuration equals to:

        getClassDirectories().setFrom(classDirectories.files.collect {
            fileTree(dir: it, exclude: ['/sub1Exclusions/**', '/sub2Exclusions/**'])
        })

but obviously programatically and not everytime specify in 2 different places (subproject and a root).

Note that the jacoco plugin is intentionally not applied to the root project.

Any ideas?