Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Html report creation hangs #509

Closed
ben-gooding-sky opened this issue Nov 20, 2023 · 16 comments
Closed

Html report creation hangs #509

ben-gooding-sky opened this issue Nov 20, 2023 · 16 comments
Assignees
Labels
Bug Bug issue type S: in progress Status: implementing or design in process

Comments

@ben-gooding-sky
Copy link

ben-gooding-sky commented Nov 20, 2023

Describe the bug
In a multi-module kotlin-only, kotlin-android project the coverage report job hangs forever
The tests all pass correctly, but once it gets to the kover portion it hangs

Errors

> Task :kover:koverHtmlReport
Kover: HTML report for ':kover' file:///${path-to-project}/kover/build/reports/kover/html/index.html
[2023.11.20 11:53:34] (Coverage): Failed to check raw report file: java.io.FileNotFoundException: ${HOME}/.gradle/daemon/8.4 (Is a directory)
[2023.11.20 11:53:34] (Coverage): Failed to load coverage data from file: ${HOME}/.gradle/daemon/8.4: java.io.FileNotFoundException: ${HOME}/.gradle/daemon/8.4 (Is a directory)
... 30+ mins

Expected behavior
It should pass almost straight away after the file not found bug occurs

Reproducer
Can't reproduce this currently on a fresh project, but occurs with
./gradlew :kover:koverHtmlReport

Reports
If applicable, report files or screenshots.

Environment

  • Kover Gradle Plugin version: 0.7.3
  • Gradle version: 8.4
  • Kotlin project type: Kotlin/JVM/Android
  • Coverage Toolset (if customized in build script): Kover
  • Other context important for this bug: MacOS apple chip + linux pipeline
@ben-gooding-sky ben-gooding-sky added Bug Bug issue type S: untriaged Status: issue reported but unprocessed labels Nov 20, 2023
@shanshin
Copy link
Collaborator

Hi,
could you clarify, is this problem reproducing stably?

@shanshin shanshin added S: waiting for clarification Status: additional information required to proceed and removed S: untriaged Status: issue reported but unprocessed labels Nov 20, 2023
@ben-gooding-sky
Copy link
Author

ben-gooding-sky commented Nov 20, 2023

Yeah it happens consistently, both locally and in the pipeline

@shanshin
Copy link
Collaborator

It seems that this is due to #478 (problem with file names), for sure we will be able to verify after the release of this change.

@shanshin shanshin added S: in progress Status: implementing or design in process and removed S: waiting for clarification Status: additional information required to proceed labels Nov 20, 2023
@ben-gooding-sky
Copy link
Author

ben-gooding-sky commented Nov 21, 2023

I've narrowed down the issue I was having, all works fine normally, but by including just this

implementation(libs.ktor)

Is causing the hanging, which is in a Kotlin JVM module

(note I've not added any code changes)

@shanshin
Copy link
Collaborator

@ben-gooding-sky , please, try 0.7.5, is the bug still reproduced?

@ben-gooding-sky
Copy link
Author

ben-gooding-sky commented Nov 28, 2023

Sadly getting a different error on 0.7.5, it's not resolving the first jvm module (working on 0.7.3) with the error

* What went wrong:
Configuration cache state could not be cached: field `provider` of `org.gradle.configurationcache.serialization.codecs.ProviderBackedFileCollectionSpec` bean found in field `__additionalArtifacts__` of task `:kover:koverGenerateArtifact` of type `kotlinx.kover.gradle.plugin.tasks.services.KoverArtifactGenerationTask`: error writing value of type 'org.gradle.api.internal.AbstractNamedDomainObjectContainer$NamedDomainObjectCreatingProvider'
> Failed to notify dependency resolution listener.

Then this x20+ times: (all exactly the same error)

Kover android variant 'customDebug' was not matched with any variant from dependency ':first-jvm-module' of project ':kover'. Check that the Kover plugin is applied in the ':first-jvm-module' project and there is a variant compatible with 'customDebug' in it.

From my understanding for multi-platform projects it should be enough to have these 2 configs in my kover module to run the tests - as described here

koverReport {
    defaults {
        mergeWith("customDebug")
    }
}

and

dependencies {
    rootProject.subprojects.forEach { project ->
         kover(project(project.path))
    }
}

and the kover plugin is applied in the root build.gradle

@shanshin
Copy link
Collaborator

Kover android variant 'customDebug' was not matched with any variant from dependency ':first-jvm-module' of project ':kover'. Check that the Kover plugin is applied in the ':first-jvm-module' project and there is a variant compatible with 'customDebug' in it.

As far as I understand, this error occurs to you if you call the :koverHtmlReportCustomDebug command?

@ben-gooding-sky
Copy link
Author

both kover:koverHtmlReportCustomDebug and kover:koverHtmlReport

@ben-gooding-sky
Copy link
Author

and both of those have the same error

@shanshin
Copy link
Collaborator

To create the correct configuration, it was useful to understand the structure of the build.
There is no universal solution for complex structures.

Is your project closed or open source?

@ben-gooding-sky
Copy link
Author

ben-gooding-sky commented Nov 28, 2023

It's closed, but I've created a similar project here that has the same issue that is open 😄

https://github.com/ben-gooding-sky/kover-bug-example

I was using this command to quickly delete the report each time + re-run kover
rm -rf kover/build/ && ./gradlew :kover:koverHtmlReport

If you change the version back down to 0.7.3 it'll work, but with .4, and .5 it fails

(note this example project doesn't show the initial hanging error I was having on 0.7.3 🤷 but it will fail without hanging even on 0.7.3 if you uncomment the line implementation(libs.ktor))

@shanshin
Copy link
Collaborator

shanshin commented Nov 28, 2023

Thanks for the example.

In the case of complex cases, it is necessary to adhere to the following rules:

  1. For independent Android projects, must be specified mergeWith() in each of them
    in your case, specify
koverReport {
    defaults {
        mergeWith("debug")
    }
}

in projects :app and :kover

  1. Create a combined report in a project that does not apply any of the Android plugins
    in your case
dependencies {
    subprojects.forEach { project ->
        kover(project)
    }
}

for example, in the root project (let's call it a merging project)

  1. Specify report filters only in the merging project
    in your case for root project specify
        koverReport {
            filters {
                excludes {
                    classes(
                        "*.BuildConfig",
                        "*.extensions.*"
                    )
                    packages("*.di", "*.ext")
                    annotatedBy("androidx.compose.ui.tooling.preview.Preview")
                    annotatedBy("androidx.compose.runtime.Composable")
                }
            }
        }

@ben-gooding-sky
Copy link
Author

Perfect thank you! - yes this got it all working (+ ktor no longer causes it to hang)

added this to my root build.gradle

subprojects {
    val subProject = this
    fun variantResolution(project: Project): String {
        return when (project.name) {
            "someModule" -> "customDebug1"
            "anotherModule" -> "customDebug2"
            else -> "debug"
        }
    }
    pluginManager.withPlugin(rootProject.libs.plugins.kover.get().pluginId) {
        pluginManager.withPlugin(rootProject.libs.plugins.android.library.get().pluginId) {
            koverReport {
                defaults {
                    mergeWith(variantResolution(subProject))
                }
            }
        }
    }
}

and stripped out everything from my kover module relating to android as you mentioned and just applied projects from there with

dependencies {
    rootProject.subprojects.forEach { project ->
        if (project.name !in excludes) {
            kover(project(project.path))
        }
    }
}

@shanshin
Copy link
Collaborator

I think we also should specify these recommendations in Kover docs

@florianflmeyer
Copy link

@ben-gooding-sky Thanks a lot for sharing this script! It's really helpful and should be part of the documentation. We can also now generate merged reports at least for all android projects. But my main question still remains and I could not find a clear answer on that:

Is it possible to create ONE report file that contains the result of both android and jvm modules?

So far the only solution I get to work it to call two gradle tasks:

  1. koverHtmlReport to create the merged report for all jvm modules
  2. koverHtmlReportDebug to create the merged report for all android modules

While this is is okay-ish, it would make things alot easier to have everything in one place.

@ben-gooding-sky
Copy link
Author

@florianflmeyer The configuration I used does work for for both Android/Jvm targets in one report using koverHtmlReport which must also be run from a module that doesn't contain any Android dependencies

  • Specifically the line mergeWith(variantResolution(subProject)) is what makes it possible to merge the reports into 1

Mentioned here in their docs

wzieba added a commit to wordpress-mobile/WordPress-Android that referenced this issue Jan 9, 2024
To combine Android and JVM projects, an additional configuration in root project was needed. Please see:

- Kotlin/kotlinx-kover#522 (comment)
- Kotlin/kotlinx-kover#509 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Bug issue type S: in progress Status: implementing or design in process
Projects
None yet
Development

No branches or pull requests

3 participants