In your app’s adle file, add the following line apply from: “ adle” so it looks like the following: apply plugin: ''. Now that we have the plugin configuration done, we need to make sure it is applied. You can find the description of each Jacoco property by following the below link. Although the Android plugin is typically updated in lock-step with Android Studio, the plugin (and the rest of the Gradle system) can run independent of Android Studio and be updated separately. If not, change the path to the directory the files now appear in. The Android Studio build system is based on Gradle, and the Android Gradle plugin adds several features that are specific to building Android apps. The same goes for the instrumentation tests.įor future reference, some Android plugin versions change the build dir hierarchy, so in case it is not working in the future, make sure the files are generated at the path you provided. If you only want to track coverage of your unit tests, don’t add the androidTestsData path. We define both of these paths using the Jacoco’s executionData property.
ec type is created for Android instrumentation files. exec file is created for the JVM unit tests and a similar file of. buildscript AndroidTest/connected/", includes: ) executionData(files())Īn. Add classpath “ org.jacoco::0.8.5 ” to your project. Jacoco pluginįirstly, you will want to add Jacoco plugin to your project.
We are going to go through how to setup Jacoco plugin, how to setup the client part of Sonar, how to be able to choose one or both the jvm and instrumentation tests code coverage and what to watch out for when using version 6.x of the Gradle plugin. I learned the plugins are quite simple to implement, so to encourage you not to use 3rd party plugins when it is not necessary, I’d like to present you with a thorough guideline. When we upgraded the Gradle plugin to the newest version ( 6.6.1 as of writing this blogpost), it wasn’t all sunshine and rainbows with the then-used 3rd party plugin as it had not been maintained for a good year. We were dealing with two issues - we were using an outdated Gradle plugin and we were missing the instrumentation test coverage in our reports. That’s history, we are now #OneJamfĪt Wandera, we have been measuring our code coverage for quite a while, but we relied on a 3rd party plugin that solved the Jacoco plugin configuration for us because we didn’t want to deal with Groovy language for speed and simplicity. This blog post was written under the Wandera brand prior to its acquisition by Jamf.
Android+Kotlin Code coverage with Jacoco, Sonar and Gradle plugin 6.x