Gradle Jacoco - Could not find method jacocoTestReport()

Guido :

I'm trying to generate a Jacoco test report in Gradle. When I try to sync my code, I will receive the following error:

Error:(56, 0) Could not find method jacocoTestReport() for arguments [build_38ehqsoyd54r3n1gzrop303so$_run_closure4@10012308] on project ':app' of type org.gradle.api.Project.

My build.gradle file contains the following items:

apply plugin: 'jacoco'

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

jacocoTestReport {
    group = "Reporting"
    reports {
        xml.enabled true
        csv.enabled false
        html.destination "${buildDir}/reports/coverage"
    }
}

When I look at the documentation , I don't see anything which I'm doing wrong.

Gradle version: 3.3

Why am I receiving this error and how can I fix it?

Christopher :

Basically I know two ways to achieve this.

The first approach is the built-in android gradle plugin feature:

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

This one will define gradle tasks, which can be executed. As far as I know this works fine with instrumentation tests. More information: Code Coverage on Android

The 2nd approach is to use this plugin:

https://github.com/vanniktech/gradle-android-junit-jacoco-plugin

Setup is easy:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
         classpath 'com.vanniktech:gradle-android-junit-jacoco-plugin:0.6.0'
    }
}

apply plugin: 'com.vanniktech.android.junit.jacoco'

And after project sync, you will have tasks like jacocoTestReport<Flavor><BuildType>

We use this to measure the code coverage of our unit tests running on the local machine.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Running JaCoCo in Azure DevOps for Android : Could not find method jacocoTestReport()

Gradle: Could not find method providedCompile()

Gradle: Could not find method provided()

Gradle could not find method c()

Gradle: Could not find method provided() (group)

Gradle error: Could not find method jar() for arguments

Gradle build: Could not find method signingConfig() for arguments

Gradle Could not find method “() for arguments on root project

Gradle Could not find method compile() for arguments

Build error with gradle Could not find method testCompile()

Gradle - Could not find method mavenRepo() for arguments

Gradle: Could not find method plugins() for arguments

Could not find method compile() for arguments Gradle

Could not find method compileOnly with Gradle 4.3.1

gradle error Could not find method dependencyManagement()

Updating gradle, Could not find method compile() for arguments

Could not find method artifactory() [Gradle 7.+]

gradle jacocoTestReport is not working?

build.gradle - Could not find method copyDeps() for arguments

Gradle error - Could not find method storeFile() for arguments /path/to/storefile

Why is my gradle build failing? (could not find method apt())

Could not find method android() for arguments org.gradle.api.Project

Gradle sync failed: Could not find method buildConfigField() android studio

Gradle sync error in Android Studio, could not find method android()

How to add dependencies using gradle? "Could not find method repositories() for arguments"

Build gradle : Could not find method packagingOptions() for arguments root Project "fasterDev"

Gradle could not find method compile() - v28?

Gradle sync failed: Could not find method compile() for arguments

Gradle error : Could not find method maybeCreate() for arguments [victims] on configuration container