The new API allows you to configure Kover in a more flexible manner, while being more concise than the previous API. From now on, there is no need to configure Kover or test tasks separately.
- applying the plugin to the root project no longer causes it to be recursively applied to all subprojects - you must explicitly apply it to all projects that will be covered
- merged tasks are not created by default. You must explicitly enable it if necessary (for details see)
- the extension
kover {}
is used to configure taskskoverXmlReport
,koverHtmlReport
,koverVerify
, test tasks, instead of configuring these tasks directly - the extension
koverMerged {}
is used to configure taskskoverMergedXmlReport
,koverMergedHtmlReport
,koverMergedVerify
, instead of configuring these tasks directly - task
koverCollectReports
was removed
In the new API, merged tasks are not created by default. To create them, you need to use the plugin in the koverMerged
extension, it is necessary to call the function enable()
.
e.g.
koverMerged.enable()
or
koverMerged {
enable()
}
or
extensions.configure<KoverMergedConfig> {
enable()
}
Now any merged tasks settings occur only in the koverMerged
extension.
By default, tasks use the results of measuring the coverage of the project in which they were created and all subprojects.
At the same time, it is important that the Kover plugin is used in all these projects, as well as that they use the same variant (vendor and version) of the coverage engine.
For example, it can be done this way
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.jetbrains.kotlinx:kover:0.6.0-Beta")
}
}
apply(plugin = "kover")
extensions.configure<KoverMergedConfig> {
enable()
// configure merged tasks
}
allprojects {
apply(plugin = "kover")
extensions.configure<KoverProjectConfig> {
// `true` - to disable the collection of coverage metrics for tests from this project
isDisabled.set(false)
// configure engine variant
engine.set(kotlinx.kover.api.IntellijEngine("1.0.657"))
// configure project's tasks if needed
}
}
In order not to use measurements from some projects now instead of disabledProjects
property for kover
extension you need to use koverMerged
extension:
extensions.configure<KoverMergedConfig> {
enable()
filters {
projects {
excludes.addAll("project-to-exclude", ":path:to:exclude")
}
}
}
Instead of configuring the merged XML report task
koverMergedXmlReport {
// config task
}
or
tasks.withType<KoverMergedXmlReportTask> {
// config task
}
you need to configure koverMerged
extension:
extensions.configure<KoverMergedConfig> {
enable()
xmlReport {
// config task
}
}
Instead of configuring the merged HTML report task
koverMergedHtmlReport {
// config task
}
or
tasks.withType<KoverMergedHtmlReportTask> {
// config task
}
you need to configure koverMerged
extension:
extensions.configure<KoverMergedConfig> {
enable()
htmlReport {
// config task
}
}
Instead of configuring the merged verification report task
koverMergedVerify {
// config task
}
or
tasks.withType<KoverMergedVerificationTask> {
// config task
}
you need to configure koverMerged
extension:
extensions.configure<KoverMergedConfig> {
enable()
verify {
// config task
}
}
Error message:
Val cannot be reassigned
Solution for Kotlin script: change isDisabled = true
to isDisabled.set(true)
Error messages:
Using 'coverageEngine: Property<CoverageEngine>' is an error
Using 'intellijEngineVersion: Property<String>' is an error
Using 'jacocoEngineVersion: Property<String>' is an error
Solution:
Use property engine
- it combines version and coverage engine vendor.
To use IntelliJ Coverage Engine with default version write engine.set(kotlinx.kover.api.DefaultIntellijEngine)
(Kotlin) or engine = kotlinx.kover.api.DefaultIntellijEngine.INSTANCE
(Groovy).
To use IntelliJ Coverage Engine with custom version write engine.set(kotlinx.kover.api.IntellijEngine("version"))
(Kotlin) or engine = kotlinx.kover.api.IntellijEngine("version")
(Groovy).
To use JaCoCo Coverage Engine with default version write engine.set(kotlinx.kover.api.DefaultJacocoEngine)
(Kotlin) or engine = kotlinx.kover.api.DefaultJacocoEngine.INSTANCE
(Groovy).
To use JaCoCo Coverage Engine with custom version write engine.set(kotlinx.kover.api.JacocoEngine("version"))
(Kotlin) or engine = kotlinx.kover.api.JacocoEngine("version")
(Groovy).
Use the properties individually for each report
kover {
xmlReport {
onCheck.set(true)
}
htmlReport {
onCheck.set(true)
}
verify {
onCheck.set(true)
}
}
Error message:
Using 'disabledProjects: Set<String>' is an error.
Solution
- read about merged reports changes
- use exclusion list in project filters of merged configuration extension
koverMerged {
enable()
filters {
projects {
excludes.add(":path or unique project name")
}
}
}
If includes
are empty, all subprojects and current project are used in merged reports.
There is no replacement. At the moment, all classes from the packages "android." and "com.android.*" excluded from instrumentation.
In the new API for single-project reports, it is impossible to call test tasks of another project. To account for coverage from tests of another module, use merged reports.
Error message
Val cannot be reassigned
Solution for Kotlin script: change isDisabled = true
to isDisabled.set(true)
Solution: change binaryReportFile
to reportFile
Solution:
includes.addAll("com.example.*", "foo.bar.*")
Solution for Kotlin: change excludes = listOf("com.example.*", "foo.bar.*")
to includes.addAll("com.example.*", "foo.bar.*")
Solution for Groovy: change excludes = ["com.example.*", "foo.bar.*"]
to includes.addAll("com.example.*", "foo.bar.*")
Solution: use property in Kover extension at the root of the project
kover {
xmlReport {
reportFile.set(yourFile)
}
}
* for xmlReportFile
task use koverMerged { ... }
extension of the project.
Solution for Kotlin: use filter in Kover extension at the root of the project
kover {
filters {
classes {
includes += listOf("foo.bar.*", "foo.biz.*")
}
}
}
Solution for Groovy: use filter in Kover extension at the root of the project
kover {
filters {
classes {
includes.addAll("foo.bar.*", "foo.biz.*")
}
}
}
* for xmlReportFile
task use koverMerged { ... }
extension of the project.
Solution for Kotlin: use filter in Kover extension at the root of the project
kover {
filters {
classes {
excludes += listOf("foo.bar.*", "foo.biz.*")
}
}
}
Solution for Groovy: use filter in Kover extension at the root of the project
kover {
filters {
classes {
excludes.addAll("foo.bar.*", "foo.biz.*")
}
}
}
* for xmlReportFile
task use koverMerged { ... }
extension of the project.
Error message:
Val cannot be reassigned
Solution:
includes.addAll("com.example.*", "foo.bar.*")
and
excludes.addAll("com.example.*", "foo.bar.*")
Error message:
Using 'KoverHtmlReportTask' is an error
Solution:
Configure report by Kover project extension
kover {
htmlReport {
// HTML report settings
}
}
Error message:
Using 'htmlReportDir: DirectoryProperty' is an error
Solution: use property reportDir
in Kover extension at the root of the project
kover {
htmlReport {
reportDir.set(yourDir)
}
}
* for koverMergedHtmlReport
task use koverMerged { ... }
extension of the project.
Error message:
Using 'includes: List<String>' is an error
Solution for Kotlin: use filter in Kover extension at the root of the project
kover {
filters {
classes {
includes += listOf("foo.bar.*", "foo.biz.*")
}
}
}
Solution for Groovy: use filter in Kover extension at the root of the project
kover {
filters {
classes {
includes.addAll("foo.bar.*", "foo.biz.*")
}
}
}
* for koverMergedHtmlReport
task use koverMerged { ... }
extension of the project.
Error message:
Using 'excludes: List<String>' is an error
Solution for Kotlin: use filter in Kover extension at the root of the project
kover {
filters {
classes {
excludes += listOf("foo.bar.*", "foo.biz.*")
}
}
}
Solution for Groovy: use filter in Kover extension at the root of the project
kover {
filters {
classes {
excludes.addAll("foo.bar.*", "foo.biz.*")
}
}
}
* for koverMergedHtmlReport
task use koverMerged { ... }
extension of the project.
Error message:
Using 'rule(Action<VerificationRule>): Unit' is an error
Solution:
use function rule
in Kover project extension
kover {
verify {
rule {
// your verification rule
}
}
}
- For
koverMergedVerify
task usekoverMerged { ... }
extension of the project.
Error message:
Using 'includes: List<String>' is an error
Solution for Kotlin: use filter in Kover extension at the root of the project
kover {
filters {
classes {
includes += listOf("foo.bar.*", "foo.biz.*")
}
}
}
Solution for Groovy: use filter in Kover extension at the root of the project
kover {
filters {
classes {
includes.addAll("foo.bar.*", "foo.biz.*")
}
}
}
* for koverMergedVerify
task use koverMerged { ... }
extension of the project.
Error message:
Using 'excludes: List<String>' is an error
Solution for Kotlin: use filter in Kover extension at the root of the project
kover {
filters {
classes {
excludes += listOf("foo.bar.*", "foo.biz.*")
}
}
}
Solution for Groovy: use filter in Kover extension at the root of the project
kover {
filters {
classes {
excludes.addAll("foo.bar.*", "foo.biz.*")
}
}
}
- For
koverMergedVerify
task usekoverMerged { ... }
extension of the project.