Gradle 6.0 deprecation warning for JacocoReport configuration

会有一股神秘感。 提交于 2020-06-10 07:28:12

问题


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 (which by their name seem to be getters and not setters):

  • getAdditionalSourceDirs().from(...)
  • getSourceDirectories().from(...)
  • getClassDirectories().from(...)
  • getExecutionData().from(...) ?

回答1:


There is a setter .from, which works 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
    ...
}


来源:https://stackoverflow.com/questions/56181089/gradle-6-0-deprecation-warning-for-jacocoreport-configuration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!