if (project.property("IS_COVERAGE_ENABLED").toString().toBoolean()) { apply(plugin = "java-library") apply(plugin = "jacoco") configure { toolVersion = project.property("JACOCO_VERSION").toString() } afterEvaluate { tasks.withType().configureEach { classDirectories.setFrom( fileTree("${buildDir}/classes/kotlin/jvm/") { exclude("**/*Test*.*", "**/*Fixture*.*") } ) sourceDirectories.setFrom( // This could be better if it dynamically got the source directories, e.g. more along the lines of // kotlin.sourceSets["commonMain"].kotlin.sourceDirectories, // kotlin.sourceSets["jvmMain"].kotlin.sourceDirectories listOf("src/commonMain/kotlin", "src/jvmMain/kotlin") ) executionData.setFrom("${buildDir}/jacoco/jvmTest.exec") } } }