28

The following Gradle task, which configures JacocoReportBase:

task jacocoRootReport(type: JacocoReport) {
    ...
    sourceDirectories = files(subprojects.sourceSets.main.allSource.srcDirs)
    additionalSourceDirs = files(subprojects.sourceSets.main.allSource.srcDirs)
    classDirectories = files(subprojects.sourceSets.main.output)
    executionData = files(subprojects.jacocoTestReport.executionData)
    ...
}

produces these warnings, when building with ./gradlew assembleDebug --warning-mode all:

The JacocoReportBase.setSourceDirectories(FileCollection) method has been deprecated.
This is scheduled to be removed in Gradle 6.0. Use getSourceDirectories().from(...)
at tasks_1p10s36ydq4k8rroeiucekewi$_run_closure6.doCall(.../tasks.gradle:152)

The JacocoReportBase.setAdditionalSourceDirs(FileCollection) method has been deprecated.
This is scheduled to be removed in Gradle 6.0. Use getAdditionalSourceDirs().from(...)
at tasks_1p10s36ydq4k8rroeiucekewi$_run_closure6.doCall(.../tasks.gradle:151)

The JacocoReportBase.setClassDirectories(FileCollection) method has been deprecated.
This is scheduled to be removed in Gradle 6.0. Use getClassDirectories().from(...)
at tasks_1p10s36ydq4k8rroeiucekewi$_run_closure6.doCall(.../tasks.gradle:153)

The JacocoReportBase.setExecutionData(FileCollection) method has been deprecated.
This is scheduled to be removed in Gradle 6.0. Use getExecutionData().from(...)
at tasks_1p10s36ydq4k8rroeiucekewi$_run_closure6.doCall(.../tasks.gradle:154)

How to use the Gradle 6.0 compatible syntax (as the deprecation warning suggests) to apply the desired values with these methods (passing the argument in brackets somehow does not work):

  • getAdditionalSourceDirs().from(...)
  • getSourceDirectories().from(...)
  • getClassDirectories().from(...)
  • getExecutionData().from(...) ?
Martin Zeitler
  • 1
  • 19
  • 155
  • 216

1 Answers1

74

Setter .from can be used alike this:

task jacocoRootReport(type: JacocoReport) {
    ...
    sourceDirectories.from = subprojects.sourceSets.main.allSource.srcDirs
    additionalSourceDirs.from = subprojects.sourceSets.main.allSource.srcDirs
    classDirectories.from = subprojects.sourceSets.main.output
    executionData.from = subprojects.jacocoTestReport.executionData
    ...
}
Martin Zeitler
  • 1
  • 19
  • 155
  • 216
  • 3
    This solution with ```classDirectories.from``` work in Gradle Springboot projects too. Thanks. – Juliano Macedo Aug 27 '19 at 14:11
  • 1
    Deprecation explanation on the method in the source code. https://github.com/gradle/gradle/blob/v5.6.4/subprojects/jacoco/src/main/java/org/gradle/testing/jacoco/tasks/JacocoReportBase.java#L108 – RenatoIvancic Aug 26 '21 at 12:57