以下Gradle任务,它配置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)
...
}
当使用./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)
如何使用与Gradle 6.0兼容的语法(如过时警告所建议)将期望的值与这些方法一起使用(按其名称,该值似乎是getter而不是setter):
getAdditionalSourceDirs().from(...)
getSourceDirectories().from(...)
getClassDirectories().from(...)
getExecutionData().from(...)
吗?答案 0 :(得分:1)
有一个设置器.from
,其工作原理如下:
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
...
}