Gradle Jacoco - Could not find method jacocoTestReport ()

I am trying to generate a Jacoco test report in Gradle. When I try to sync my code, I get the following error:

Error: (56, 0) Could not find jacocoTestReport () method for arguments [build_38ehqsoyd54r3n1gzrop303so $ _run_closure4 @ 10012308] in 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 can't see anything I am doing wrong.

Gradle version: 3.3

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

+3


source to share


2 answers


Basically I know two ways to achieve this.

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

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

      

This will define the gradle tasks that can be done. As far as I know, this works great with instrumental tests. More information: Code wrapper on Android

The second approach is to use this plugin:



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

The setup is simple:

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

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

      

And after synchronizing the project, 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.

+4


source


As stated in the documentation mentioned in your question :

If the Java plugin is also applied to your project, a new task named jacocoTestReport is created that depends on the test task.



which is quite logical - measuring the coverage for Java code requires compiling it, running tests, etc.

So using your example build.gradle

causes a crash that goes away after adding apply plugin: 'java'

.

+2


source







All Articles