Gradle Jacoco - Could not find method jacocoTestReport()
android, gradle, jacoco, java
Solution
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.
Problem
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?