简体   繁体   English

无法添加任务':jacocoTestReport'作为具有该名称的任务已存在

[英]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 : 我正在尝试添加以下任务,以便我可以在我的java + kotlin项目中获取一些覆盖数据(对于它的价值,这是一个gradle项目)...但是我收到以下错误:

"Cannot add task ':jacocoTestReport' as a task with that name already exists" “无法添加任务':jacocoTestReport'作为具有该名称的任务已经存在”

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. 我意识到这不是java或kotlin特定的问题 - 但由于它是一个联合的java + kotlin项目,我想我会在这个问题中标记两个,以防有其他人见过的细微问题。

Assuming you're already applying the Jacoco Gradle plugin, then yes, it already defines a task called jacocoTestReport , hence the error. 假设您已经应用了Jacoco Gradle插件,那么是的,它已经定义了一个名为jacocoTestReport的任务,因此错误。

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 您需要做的就是根据文档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. 您列出的大多数其他配置项都属于'jacoco'配置块。 https://docs.gradle.org/current/userguide/jacoco_plugin.html#sec:jacoco_specific_task_configuration https://docs.gradle.org/current/userguide/jacoco_plugin.html#sec:jacoco_specific_task_configuration

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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