Search code examples
gradlejacoco-plugin

Jacoco nodeps: ClassNotFound com.vladium.emma.rt.RT


Description

Gradle 5.6.4

Android Studio 3.6.3

Problem

In a file under the androidTest directory, I had such a line of code and got ClassNotFoundException.

Class<?> emmaRTClass = Class.forName("com.vladium.emma.rt.RT");

Project Structure

.
├── build.gradle
├── subproject.main (app)
       ├── src
       ├── ...
       └── build.gradle
├── subproject1
├── subproject2
 ...

build.gradle

./build.gradle

buildscript {
    ext.jacocoVersion="0.8.2"
    ...
    dependencies {
         ...
         classpath "org.jacoco:org.jacoco.core:$jacocoVersion"
    }
}

subproject.main/build.gradle

...
dependencies {
     ...
     jacocoAnt 'org.jacoco:org.jacoco.ant:0.8.1:nodeps'
}

apply plugin: 'jacoco'
...

According to this,

| org.jacoco | org.jacoco.ant | nodeps | Ant Tasks (all dependencies included) |

gradle dependencies:

To see the dependencies for subproject.main

 $ ./gradlew app:dependencies | grep jacoco

The output is

jacocoTestReport_test
jacocoAgent - The Jacoco agent to use to get coverage data.
\--- org.jacoco:org.jacoco.agent:0.8.2
jacocoAnt - The Jacoco ant tasks to use to get execute Gradle tasks.
\--- org.jacoco:org.jacoco.ant:0.8.1
     +--- org.jacoco:org.jacoco.core:0.8.1
     +--- org.jacoco:org.jacoco.report:0.8.1
     |    \--- org.jacoco:org.jacoco.core:0.8.1 (*)
     \--- org.jacoco:org.jacoco.agent:0.8.1
jacocoRuntime

ls ~/.gradle/caches/modules-2/files-2.1

 org.jacoco
 ├── org.jacoco.core
 └── org.jacoco.report

Solution

  • Finally I got it! It is because the default value of testCoverageEnabled is false as shown in the following configuration. Just set testCoverageEnabled true unconditionally.

    buildTypes {
        debug {
           ...
           if (isFromServer()) {
               testCoverageEnabled true
           }
        }
    }