我目前正在我的团队构建的Android代码库中设置Jacoco.我对Android没有太多经验,但我以前在Spring Boot代码库中设置过Jacoco,这样我就可以在Sonarqube中跟踪测试覆盖率.但我在Android代码库方面做得很艰难.
因此,目录布局如下所示
MyApp/
├─ app/
│ ├─ build/
│ ├─ src/
│ ├─ build.gradle.kts
├─ buildSrc/
│ ├─ build.gradle.kts
├─ modules/
│ ├─ module1/
│ │ ├─ src/
│ │ ├─ build.gradle.kts
│ ├─ module2/
│ │ ├─ src/
│ │ ├─ build.gradle.kts
├─ build.gradle.kts
├─ gradle.properties
├─ gradlew
├─ settings.gradle.kts
我试着在MyApp/build.gradle.kts
中加jacoco
.
plugins {
id(Dependencies.Plugins.androidApplication) version Dependencies.Versions.androidAppplication apply false
id(Dependencies.Plugins.androidLibrary) version Dependencies.Versions.androidLibrary apply false
id(Dependencies.Plugins.hilt) version Dependencies.Versions.hilt apply false
id(Dependencies.Plugins.openApi) version Dependencies.Versions.openApi
id(Dependencies.Plugins.kotlinAndroid) version Dependencies.Versions.kotlinAndroid apply false
id(Dependencies.Plugins.sonarqube) version Dependencies.Versions.sonarqube
id("jacoco")
}
我试着处死bash gradlew test jacocoTestReport
人,但上面写着
Task 'jacocoTestReport' not found in root project 'MyApp' and its subprojects.
根据JaCoco插件文档(https://docs.gradle.org/current/userguide/jacoco_plugin.html),我try 在MyApp/build.gradle.kts
中添加以下代码行
tasks.test {
finalizedBy(tasks.jacocoTestReport) // report is always generated after tests run
}
tasks.jacocoTestReport {
dependsOn(tasks.test) // tests are required to run before generating the report
}
但输出内容如下所示
Script compilation errors:
Line 12: tasks.test {
^ Unresolved reference: test
Line 13: finalizedBy(tasks.jacocoTestReport)
^ Unresolved reference: finalizedBy
我在一个运行正常的Spring Boot项目中进行了类似的配置.但在这里,它甚至无法检测到任务jacocoTestReport
.
我做错什么了?