Jacoco 节点:ClassNotFound com.vladium.emma.rt.RT
Jacoco nodeps: ClassNotFound com.vladium.emma.rt.RT
描述
Gradle 5.6.4
Android Studio 3.6.3
问题
在androidTest
目录下的一个文件中,有这么一行代码,得到了ClassNotFoundException
.
Class<?> emmaRTClass = Class.forName("com.vladium.emma.rt.RT");
项目结构
.
├── 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'
...
根据this,
| org.jacoco | org.jacoco.ant | nodeps | Ant Tasks (all dependencies included) |
gradle 依赖关系:
查看 subproject.main
的依赖项
$ ./gradlew app:dependencies | grep jacoco
输出为
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
我终于明白了!这是因为testCoverageEnabled
的默认值是false
,如下配置所示。 无条件设置testCoverageEnabled true
即可。
buildTypes {
debug {
...
if (isFromServer()) {
testCoverageEnabled true
}
}
}
描述
Gradle 5.6.4
Android Studio 3.6.3
问题
在androidTest
目录下的一个文件中,有这么一行代码,得到了ClassNotFoundException
.
Class<?> emmaRTClass = Class.forName("com.vladium.emma.rt.RT");
项目结构
.
├── 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'
...
根据this,
| org.jacoco | org.jacoco.ant | nodeps | Ant Tasks (all dependencies included) |
gradle 依赖关系:
查看 subproject.main
$ ./gradlew app:dependencies | grep jacoco
输出为
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
我终于明白了!这是因为testCoverageEnabled
的默认值是false
,如下配置所示。 无条件设置testCoverageEnabled true
即可。
buildTypes {
debug {
...
if (isFromServer()) {
testCoverageEnabled true
}
}
}