Open mattinger opened 4 years ago
Feel free to create a PR!
I can likely do that. I just have to get approval for submission (lawyers)
Sure!
@braedongough could you please review
@dominiquejb plz have braedongough review
Hi @mattinger. I know it is pretty old, but did you have the opportunity to get approval?
I couldn't make @mattinger solution work. Firstly, I had to delete 'val' keywords and 'as? ...' conversion since I use Groovy instead of Kotlin, after this it told me about missing property skippedProjects
, I deleted it. After that, I changed to my product flavor. Eventually, it tells me that build is successful for this task, but it doesn't correctly check limits (it doesn't report errors).
To make it work, I used the solution from this root build gradle which is described in this video which eventually tells me Rule violated for bundle app: instructions covered ratio is 0.3, but expected minimum is 0.8
as expected.
The code in my case added to root's build.gradle. Note that I use my product flavor Mock
in 3 places, so you need to change it to your flavor or delete it if your don't use flavors in your project
subprojects {
afterEvaluate() {
tasks.register('verifyCodeCoverageMockDebug', JacocoCoverageVerification) {
dependsOn 'jacocoTestReportMockDebug'
sourceDirectories.from = file("${project.projectDir}/src/main/java") // main source set
classDirectories.from = files(JacocoUtil.getKotlinFileTree(project))
executionData.from = fileTree(dir: project.buildDir, includes: [
'**/*.exec', // unit tests
'**/*.ec' // ui tests
])
violationRules {
rule {
limit {
minimum = 0.8 // 30%
}
}
}
}
}
}
class JacocoUtil {
static ConfigurableFileTree getKotlinFileTree(Project project) {
return project.fileTree(
// Where generated Kotlin classes are located
dir: "$project.buildDir/tmp/kotlin-classes/mockDebug",
// Exclude everything that is not created by you, e.g. created by HILT
excludes: [
'**/BuildConfig.*',
'**/*$*',
'**/Hilt_*.class',
'hilt_**',
'dagger/hilt/**',
'**/*JsonAdapter.*'
]
)
}
}
It would be awesome if the plugin would also include configuration of the appropriate tasks of type JacocoCoverageVerification. Right now, i have to kind of hack around this by doing lazy creation of the task (due to the use of afterEvaluate to define the tasks in the plugin. I can then find the reporting task and copy the configuration from that into the verification task that gets created.
Obviously this is hokey, and would be better done in the plugin.