Jacoco for gradle kts

Tram Ho

Jacoco has been a tool for testing test coverage for a long time, we often configure jacoco in an .gradle file and add it to the build.gradle of the app module when we want to check coverage.

Recently the gradle using kotlin in gradle kts makes it easier to configure with kotlin code instead of groovy as before.

However, currently gradle does not support adding jacoco from separate gradle.kts file, so we will need to add jacoco code to the gradle.kts file of module that needs check coverage.

Below is an example of a jacoco config for gradle kts that you can refer to

You can refer to the source code here https://github.com/dangquanuet/The-Movie-DB-Kotlin/blob/develop/app/build.gradle.kts#L29

Then you can proceed to run test coverage as usual with jacoco before it is via the command line or gradle task.

This is the end of this post, see you later ?

Share the news now

Source : Viblo