My android app is multi module project:
include (android-app/kotlin-android)\':application\', (pure kotlin)\':presentation\', (pure kotlin)\':domain\', (andr
Although the solution from @Hype works, it also messes a bit the environment as you end up with kotlin class files and META-INF in the same directory as the class files from java. This might give you some issues running the compilation for a second time.
Another solution would be to just add the path for kotlin classes to jacoco configuration parameter classDirectories
.
This solution would simply tell jacoco that it needs to evaluate files from two different file trees. The upside is that it does not change your environment.
Here's a sample of how you could combine class files from multiple directories, excluding any unwanted files (this is depending on your project setup, you might use dagger and have to exclude dagger generated files):
def javaAndKotlinClassFiles = files(fileTree(dir: "${project.buildDir}/intermediates/classes/${sourcePath}",
excludes: ['**/R.class',
'**/R$*.class',
'**/*$ViewInjector*.*',
'**/*$ViewBinder*.*',
'**/BuildConfig.*',
'**/Manifest*.*',
'**/*$Lambda$*.*', // Jacoco can not handle several "$" in class name.
'**/*_Provide*Factory*.*',
'**/*$*$*.*', // Anonymous classes generated by kotlin
'**/*Test*.*', // Test files
'**/*Spec*.*' // Test files
]
).files)
.from(files(fileTree(dir: "${project.buildDir}/tmp/kotlin-classes/${sourcePath}",
excludes: ['**/R.class',
'**/R$*.class',
'**/*$ViewInjector*.*',
'**/*$ViewBinder*.*',
'**/BuildConfig.*',
'**/Manifest*.*',
'**/*$Lambda$*.*', // Jacoco can not handle several "$" in class name.
'**/*_Provide*Factory*.*',
'**/*$*$*.*', // Anonymous classes generated by kotlin
'**/*Test*.*', // Test files
'**/*Spec*.*' // Test files
]).files)
)
classDirectories = javaAndKotlinClassFiles
Here's a nice guide for how to set it up for Java.