简体   繁体   中英

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

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM