Kotlin / kotlinx-kover

Apache License 2.0
1.28k stars 48 forks source link

kover(html/xml)Report(Variant) tasks cache #329

Closed vlohachov closed 1 year ago

vlohachov commented 1 year ago

Describe the bug When I add a new class, move current one to different package or basically in case of any changes kover produces same report over and over. I tried to chain 'kover(Html/Xml)Report(Variant)' task with leading 'clean' like following (./gradlew clean koverHtmlReport)) but it doesn't usually help. The only thing that helped me to solve this issue is:

tasks.whenTaskAdded { task ->
    if (task.name == 'koverHtmlReport') {
        task.outputs.upToDateWhen { false }
    }
}

Errors No errors produced

Expected behavior A clear and concise description of what you expected to happen.

Reports If applicable, report files or screenshots.

Environment

shanshin commented 1 year ago

Hi, may you clarify, does the compilation task executed when the code changes?

If the build cache is enabled, the report generation task is started only when the code is recompiled or tests are actually run. If the compilation tasks have one of these statuses FROM-CACHE, SKIPPED, UP-TO-DATE, then they were not executed and do not invalidate the report generation task cache.

vlohachov commented 1 year ago

Yes they are executed and there are no FROM-CACHE, SKIPPED, UP-TO-DATE are present in logs next to tasks.

shanshin commented 1 year ago

In this case, a reproducer is needed.

However, it is not entirely clear how the

tasks.whenTaskAdded { task ->
    if (task.name == 'koverHtmlReport') {
        task.outputs.upToDateWhen { false }
    }
}

code helped.

In 0.7.0-Alpha version, task koverHtmlReport is not used for Android applications - it is used only for JVM and Kotlin MPP/JVM projects

vlohachov commented 1 year ago

I'll provide one later today or tomorrow

My project contains couple of kotlin library modules, that's how I invalidate koverHtmlReport cache for these modules, for android ones I use koverHtmlReportDebug comparison (I've configured reports for android modules only for 'debug')

vlohachov commented 1 year ago

Well, apparently the issue is with our project structure and config, not able to reproduce this issue with "demo" project and not able to share project that faced this issue as it is in private company repo. Gonna close this issue, sorry bothering you.

armatys commented 1 year ago

I'm facing a similar (if not the same) issue. My setup:

Steps:

Task :app:koverHtmlReport UP-TO-DATE Kover: HTML report for ':app' file:///Users/mako/Developer/KoverTest/app/build/reports/kover/html/index.html

BUILD SUCCESSFUL in 1s 23 actionable tasks: 2 executed, 21 up-to-date


The timestamp in unit test report is updated, but the timestamp in HTML kover report is not.

----------

Another case (but this time with `--rerun-tasks` flag):
- Run `./gradlew clean`
- Run `./gradlew koverHtmlReport`
- HTML report is generated at `app/build/reports/kover/html/index.html`
- Comment out the `test2` function
- Run `./gradlew koverHtmlReport --rerun-tasks` again
- Result: the tests are run, report is generated, but it shows that the last line in the `Sample` class is covered (`return x + y`), but it is not covered, since we've commented out the corresponding test. Output:

...

Task :app:testDebugUnitTest Task :app:koverGenerateArtifactDebug Task :app:koverGenerateArtifact

Task :app:koverHtmlReport Kover: HTML report for ':app' file:///Users/mako/Developer/KoverTest/app/build/reports/kover/html/index.html

BUILD SUCCESSFUL in 5s 23 actionable tasks: 23 executed



To get updated kover results I'd have to run `./gradlew clean` first.
vlohachov commented 1 year ago

I'm facing a similar (if not the same) issue. My setup:

* Android Studio Android Studio Flamingo | 2022.2.1 Patch 1 (current version)

* Java 17 (bundled with Android Studio)

* Kover [0.7.0](https://github.com/Kotlin/kotlinx-kover/releases/tag/v0.7.0)

* https://github.com/armatys/KoverTest (simple android project created with Android Studio)

Steps:

* Run `./gradlew koverHtmlReport`

* HTML report is generated at `app/build/reports/kover/html/index.html`

* Change either the `SampleTest` (e.g. comment out whole `test2` function), or the change the `Sample` class (e.g. remove the `if (y == 0)` block)

* Run `./gradlew koverHtmlReport` again

* Result - kover report is not updated:
...
> Task :app:processDebugUnitTestJavaRes NO-SOURCE
> Task :app:testDebugUnitTest
> Task :app:koverGenerateArtifactDebug
> Task :app:koverGenerateArtifact UP-TO-DATE

> Task :app:koverHtmlReport UP-TO-DATE
Kover: HTML report for ':app' file:///Users/mako/Developer/KoverTest/app/build/reports/kover/html/index.html

BUILD SUCCESSFUL in 1s
23 actionable tasks: 2 executed, 21 up-to-date

The timestamp in unit test report is updated, but the timestamp in HTML kover report is not.

Another case (but this time with --rerun-tasks flag):

* Run `./gradlew clean`

* Run `./gradlew koverHtmlReport`

* HTML report is generated at `app/build/reports/kover/html/index.html`

* Comment out the `test2` function

* Run `./gradlew koverHtmlReport --rerun-tasks` again

* Result: the tests are run, report is generated, but it shows that the last line in the `Sample` class is covered (`return x + y`), but it is not covered, since we've commented out the corresponding test. Output:
...
> Task :app:testDebugUnitTest
> Task :app:koverGenerateArtifactDebug
> Task :app:koverGenerateArtifact

> Task :app:koverHtmlReport
Kover: HTML report for ':app' file:///Users/mako/Developer/KoverTest/app/build/reports/kover/html/index.html

BUILD SUCCESSFUL in 5s
23 actionable tasks: 23 executed

To get updated kover results I'd have to run ./gradlew clean first.

./gradlew --no-build-cache clean koverXmlReport is a remedy for me at the moment

bakjoul commented 1 year ago

So from what i understand, there's no real fix yet and we have to do with a clean before.

shanshin commented 1 year ago

@bakjoul, #371 was closed automatically, the fix will be included in the next release