Kotlin/kotlinx-kover

Inconsistence between koverVerify and koverVerifyJvm

MessiasLima opened this issue · 5 comments

Describe the bug
In a Kotlin multiplatform environment, there is an inconsistency between the tasks koverVerify and koverVerifyJvm.

Where running the latter, the coverage verification isn't working and the tasks always succeeds.

Errors
When running regular verify

❯ ./gradlew clean koverVerify   
Reusing configuration cache.
> Task :koverVerify FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':koverVerify'.
> Rule violated:
    lines covered percentage is 0.000000, but expected minimum is 90
    instructions covered percentage is 0.000000, but expected minimum is 90


* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

BUILD FAILED in 2s
55 actionable tasks: 50 executed, 5 up-to-date
Configuration cache entry reused.

when running the JVM variant

❯ ./gradlew clean koverVerifyJvm
Reusing configuration cache.

BUILD SUCCESSFUL in 1s
19 actionable tasks: 15 executed, 4 up-to-date
Configuration cache entry reused.

Expected behavior
Both should give the same result, since in my project, all code is on common source set

Reproducer
Kover config on root build.gradle.kts

dependencies {
    kover(project(":compose")) // compose is the shared module
}

kover {
    reports {
        filters {
            excludes {
                classes(
                    "Res*",
                )

                packages("is_cidadao.compose.generated.resources")
            }
        }

        verify {
            rule {
                disabled = false
                bound {
                    minValue = 90
                    coverageUnits = CoverageUnit.LINE
                    aggregationForGroup = AggregationType.COVERED_PERCENTAGE
                }

                bound {
                    minValue = 90
                    coverageUnits = CoverageUnit.INSTRUCTION
                    aggregationForGroup = AggregationType.COVERED_PERCENTAGE
                }

                bound {
                    minValue = 90
                    coverageUnits =  CoverageUnit.BRANCH
                    aggregationForGroup = AggregationType.COVERED_PERCENTAGE
                }
            }
        }
    }
}

on compose build gradle file I have the Kover plugin applied like..

// ./compose/build.gradle.kts
plugins {
    ...
    alias(libs.plugins.kover)
    ...
}

Reports
If applicable, report files or screenshots.

Environment

  • Kover Gradle Plugin version: 0.8.3
  • Gradle version: 8.7
  • Kotlin project type: Kotlin/Multiplatform
  • Coverage Toolset (if customized in build script): Kover
  • Other context important for this bug: [e.g. OS version]

Hi, could you clarify, is there Android build variants in your project?

Hi, could you clarify, is there Android build variants in your project?

Hi! I currently have Android, JVM (Desktop) and iOS targets.

Is there a jvm target in the root project?

I recommend using the full path to run tasks.

If in your case the verification rules are written in the root project, then you need to call the verification task only for this root report (:koverVerifyJvm).

If you write it down in a simple form ./gradlew clean koverVerifyJvm, then the task named koverVerifyJvm will be executed in all projects in which it is present. But for example, it may not be present in the root project, so the verification rules will not be taken into account

When I run :koverVerifyJvm it says this task does not exists

I created a project as a minimal setup to reproduce de issue. Could you please check it? https://github.com/MessiasLima/kover-verify-jvm-issue

When I run :koverVerifyJvm it says this task does not exists

Yes, this is expected because there are no jvm targets in the root project.
To create merged reports, it is necessary that all projects have the same report variant.

If there are different report variants in different projects, the easiest way is to create a custom common variant, as in the example.

As well as an alternative, consider using the Aggregation settings plugin plugin. It is easier to use, however, at the moment there are no some settings, and so far there is no validation (will be added in the next release)