Android Studio:找不到org.jacoco:org.jacoco.agent:org.gradle.testing.jacoco.plugins.JacocoPluginExtension_Decorated

时间:2019-02-27 10:28:51

标签: android gradle sonarqube jacoco

我正在尝试将JaCoCo添加到我的Android中,以获得Sonar Qube的承保范围。但是在运行命令./gradlew jacocoTestReport时出现以下错误。

 Task :app:testAlphaReleaseUnitTest FAILED


 FAILURE: Build failed with an exception.

出了什么问题

Could not resolve all files for configuration ':app:jacocoAgent'.
> Could not find org.jacoco:org.jacoco.agent:org.gradle.testing.jacoco.plugins.JacocoPluginExtension_Decorated.
  Searched in the following locations:
    - file:/Users/atif/Library/Android/sdk/extras/m2repository/org/jacoco/org.jacoco.agent/org.gradle.testing.jacoco.plugins.JacocoPluginExtension_Decorated/org.jacoco.agent-org.gradle.testing.jacoco.plugins.JacocoPluginExtension_Decorated.pom
    - file:/Users/atif/Library/Android/sdk/extras/m2repository/org/jacoco/org.jacoco.agent/org.gradle.testing.jacoco.plugins.JacocoPluginExtension_Decorated/org.jacoco.agent-org.gradle.testing.jacoco.plugins.JacocoPluginExtension_Decorated.421021a4
    - file:/Users/atif/Library/Android/sdk/extras/google/m2repository/org/jacoco/org.jacoco.agent/org.gradle.testing.jacoco.plugins.JacocoPluginExtension_Decorated/org.jacoco.agent-org.gradle.testing.jacoco.plugins.JacocoPluginExtension_Decorated.pom
    - file:/Users/atif/Library/Android/sdk/extras/google/m2repository/org/jacoco/org.jacoco.agent/org.gradle.testing.jacoco.plugins.JacocoPluginExtension_Decorated/org.jacoco.agent-org.gradle.testing.jacoco.plugins.JacocoPluginExtension_Decorated.421021a4
    - file:/Users/atif/Library/Android/sdk/extras/android/m2repository/org/jacoco/org.jacoco.agent/org.gradle.testing.jacoco.plugins.JacocoPluginExtension_Decorated/org.jacoco.agent-org.gradle.testing.jacoco.plugins.JacocoPluginExtension_Decorated.pom
    - file:/Users/atif/Library/Android/sdk/extras/android/m2repository/org/jacoco/org.jacoco.agent/org.gradle.testing.jacoco.plugins.JacocoPluginExtension_Decorated/org.jacoco.agent-org.gradle.testing.jacoco.plugins.JacocoPluginExtension_Decorated.421021a4
    - https://jcenter.bintray.com/org/jacoco/org.jacoco.agent/org.gradle.testing.jacoco.plugins.JacocoPluginExtension_Decorated/org.jacoco.agent-org.gradle.testing.jacoco.plugins.JacocoPluginExtension_Decorated.pom
    - https://jcenter.bintray.com/org/jacoco/org.jacoco.agent/org.gradle.testing.jacoco.plugins.JacocoPluginExtension_Decorated/org.jacoco.agent-org.gradle.testing.jacoco.plugins.JacocoPluginExtension_Decorated.421021a4
    - https://dl.google.com/dl/android/maven2/org/jacoco/org.jacoco.agent/org.gradle.testing.jacoco.plugins.JacocoPluginExtension_Decorated/org.jacoco.agent-org.gradle.testing.jacoco.plugins.JacocoPluginExtension_Decorated.pom
    - https://dl.google.com/dl/android/maven2/org/jacoco/org.jacoco.agent/org.gradle.testing.jacoco.plugins.JacocoPluginExtension_Decorated/org.jacoco.agent-org.gradle.testing.jacoco.plugins.JacocoPluginExtension_Decorated.421021a4
    - https://maven.fabric.io/public/org/jacoco/org.jacoco.agent/org.gradle.testing.jacoco.plugins.JacocoPluginExtension_Decorated/org.jacoco.agent-org.gradle.testing.jacoco.plugins.JacocoPluginExtension_Decorated.pom
    - https://maven.fabric.io/public/org/jacoco/org.jacoco.agent/org.gradle.testing.jacoco.plugins.JacocoPluginExtension_Decorated/org.jacoco.agent-org.gradle.testing.jacoco.plugins.JacocoPluginExtension_Decorated.421021a4
    - https://jcenter.bintray.com/org/jacoco/org.jacoco.agent/org.gradle.testing.jacoco.plugins.JacocoPluginExtension_Decorated/org.jacoco.agent-org.gradle.testing.jacoco.plugins.JacocoPluginExtension_Decorated.pom
    - https://jcenter.bintray.com/org/jacoco/org.jacoco.agent/org.gradle.testing.jacoco.plugins.JacocoPluginExtension_Decorated/org.jacoco.agent-org.gradle.testing.jacoco.plugins.JacocoPluginExtension_Decorated.421021a4
    - https://maven.fabric.io/public/org/jacoco/org.jacoco.agent/org.gradle.testing.jacoco.plugins.JacocoPluginExtension_Decorated/org.jacoco.agent-org.gradle.testing.jacoco.plugins.JacocoPluginExtension_Decorated.pom
    - https://maven.fabric.io/public/org/jacoco/org.jacoco.agent/org.gradle.testing.jacoco.plugins.JacocoPluginExtension_Decorated/org.jacoco.agent-org.gradle.testing.jacoco.plugins.JacocoPluginExtension_Decorated.421021a4
    - https://dl.google.com/dl/android/maven2/org/jacoco/org.jacoco.agent/org.gradle.testing.jacoco.plugins.JacocoPluginExtension_Decorated/org.jacoco.agent-org.gradle.testing.jacoco.plugins.JacocoPluginExtension_Decorated.pom
    - https://dl.google.com/dl/android/maven2/org/jacoco/org.jacoco.agent/org.gradle.testing.jacoco.plugins.JacocoPluginExtension_Decorated/org.jacoco.agent-org.gradle.testing.jacoco.plugins.JacocoPluginExtension_Decorated.421021a4
    - https://repo.maven.apache.org/maven2/org/jacoco/org.jacoco.agent/org.gradle.testing.jacoco.plugins.JacocoPluginExtension_Decorated/org.jacoco.agent-org.gradle.testing.jacoco.plugins.JacocoPluginExtension_Decorated.pom
    - https://repo.maven.apache.org/maven2/org/jacoco/org.jacoco.agent/org.gradle.testing.jacoco.plugins.JacocoPluginExtension_Decorated/org.jacoco.agent-org.gradle.testing.jacoco.plugins.JacocoPluginExtension_Decorated.421021a4
  Required by:
      project :app

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

这是我的gradle个文件:

项目build.gradle

buildscript{
    dependencies {
        classpath "org.jacoco:org.jacoco.core:0.8.2"
        classpath "org.jacoco:org.jacoco.agent:0.8.2"
    }
}

plugins {
    id "jacoco"
}

App build.gradle

plugins {
    id "com.android.application"
    id "jacoco-android"
    id "org.sonarqube" version "2.6"
}

android {
    buildTypes {
        debug {
            testCoverageEnabled = true
        }
    }
}

android.testOptions {
    unitTests.all {
        jacoco {
            includeNoLocationClasses = true
        }
    }
}

jacoco {
    toolVersion = "0.8.2"
    reportsDir = file("$buildDir/reports/jacoco/")
}

jacocoAndroidUnitTestReport {
    csv.enabled false
    html.enabled false
    xml.enabled true
}

3 个答案:

答案 0 :(得分:2)

一个是Gradle插件,它属于根项目的buildscript依赖项:

buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath "com.dicedmelon.gradle:jacoco-android:0.1.4"
        classpath "com.android.tools.build:gradle:3.2.1"
        classpath "org.jacoco:org.jacoco.core:0.8.3"
        ...
    }
}

另一个是库,它属于模块的Java依赖项:

apply plugin: "com.android.application"
// apply plugin "jacoco"
apply plugin: "jacoco-android"

...

dependencies {
    ...
    testImplementation "org.jacoco:org.jacoco.agent:0.8.3"
}

jacoco-android GitHub关于apply plugin "jacoco"的内容一无所获,但这可能是必需的。

答案 1 :(得分:0)

穆罕默德这是我与常规gradle jacoco插件一起使用的代码

它甚至设置为默认情况下同时收集浓缩咖啡和汤匙东西

jacoco {     toolVersion =“ 0.8.2”     //可以这样指定自定义报告目录:     reportsDir = file(“ $ buildDir / outputs / reports / jacoco”)

} task.withType(Test){     jacoco.includeNoLocationClasses = true } 任务jacocoTestReport(type:JacocoReport,dependsOn:['testDebugUnitTest','createDebugCoverageReport']){

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

def fileFilter = ['**/R.class', '**/R$*.class', '**/BuildConfig.*', '**/Manifest*.*', '**/*Test*.*', 'android/**/*.*']
def debugTree = fileTree(dir: "${buildDir}/intermediates/classes/debug", excludes: fileFilter)
def mainSrc = "${project.projectDir}/src/main/java"

getSourceDirectories().setFrom(files([mainSrc]))
//sourceDirectories = files([mainSrc])
//classDirectories = files([debugTree])
getClassDirectories().setFrom(files([debugTree]))
getExecutionData().setFrom(fileTree(dir: "$buildDir", includes: [
        "jacoco/testDebugUnitTest.exec",
        "**/io.gitlab.fredgrott.droidkotlinkit.*/coverageExecutionData/spoonCoverage.ec",
        "outputs/code-coverage/connected/*coverage.ec"
]))

}

答案 2 :(得分:0)

您没有在构建中定义存储库。对于许多人来说,这就是Maven Central。

repositories {
    mavenCentral()
}

似乎您要在指向lib文件夹时自己管理库。我假设这些库已通过您的源代码签入?如果将相同的策略应用于JaCoCo库,则需要将其放在此处并将其分配给JaCoCo插件的配置。