Cannot add task ':jacocoTestReport' as a task with that name already exists

社会主义新天地 提交于 2019-12-24 07:25:04

问题


I am trying to add the following task so that I can get some coverage data in my java + kotlin project (for what it is worth, this is a gradle project)... but I get the following error :

"Cannot add task ':jacocoTestReport' as a task with that name already exists"

Here is the actual task I am trying to add :

task jacocoTestReport(type: JacocoReport, dependsOn: "testDebugUnitTest") {
group = "Reporting"
description = "Generate Jacoco coverage reports for Debug build"

reports {
    xml.enabled = true
    html.enabled = true
}

// what to exclude from coverage report
// UI, "noise", generated classes, platform classes, etc.
def excludes = [
        '**/R.class',
        '**/R$*.class',
        '**/*$ViewInjector*.*',
        '**/BuildConfig.*',
        '**/Manifest*.*',
        '**/*Test*.*',
        'android/**/*.*',
        '**/*Fragment.*',
        '**/*Activity.*'
]
// generated classes
classDirectories = fileTree(
        dir: "$buildDir/intermediates/classes/debug",
        excludes: excludes
) + fileTree(
        dir: "$buildDir/tmp/kotlin-classes/debug",
        excludes: excludes
)

// sources
sourceDirectories = files([
        android.sourceSets.main.java.srcDirs,
        "src/main/kotlin"
])
    executionData = files("$buildDir/jacoco/testDebugUnitTest.exec")
}

Now, the issue I am confused about here, is that I can't find another class of this name anywhere... so perhaps there is something funky going on? I have tried googling this, but haven't really been able to find anything which truly helps me solve the problem.

All help greatly appreciated. I realize this is not a java or kotlin specific problem - but since it is a joint java + kotlin project, I thought I would tag both in this question, in case there is some nuanced issue that somebody else has seen.


回答1:


Assuming you're already applying the Jacoco Gradle plugin, then yes, it already defines a task called jacocoTestReport, hence the error.

All you need to do is define your specific settings as per the documentation https://docs.gradle.org/current/userguide/jacoco_plugin.html#sec:jacoco_report_configuration

an example is below:

jacocoTestReport {
  dependsOn "testDebugUnitTest"
    reports {
        xml.enabled = true
        html.enabled = true
    }
}

Most of the other configuration items you've listed belong in the 'jacoco' configuration block. https://docs.gradle.org/current/userguide/jacoco_plugin.html#sec:jacoco_specific_task_configuration



来源:https://stackoverflow.com/questions/49372067/cannot-add-task-jacocotestreport-as-a-task-with-that-name-already-exists

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