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

koverMergedHtmlReport seems to be stuck when switching to JacocoEngine #285

Closed
sonrohan opened this issue Dec 4, 2022 · 6 comments
Closed
Assignees
Labels
Bug Bug issue type S: waiting for clarification Status: additional information required to proceed

Comments

@sonrohan
Copy link

sonrohan commented Dec 4, 2022

Describe the bug
When running kover in my muiltiplatform + android project, koverMergedHtmlReport step seems to get stuck.

If I use the default Intellij engine, it all works fine! But I have to use jacoco, because another tool that we use only accepts jacoco.

I also tried this in a CI environment with no caches or anything like that, and experienced the same thing.

Errors
This is the problem. I get no error logs in console (even with stacktrace/-d), and I see no error in the kover/ directories. That is why I have no clue how to debug this, except through trial and error.

Expected behavior
It should run the tests and generate a merged report, just as it does when I do not specify an engine.

Reproducer
The project is like this

root/
app/ (android)
core/ (android)
xyz/ (some library, not necessarily android)
domain/ (kotlin multiplatorm)

Main build.gradle

plugins {
    id("org.jetbrains.kotlinx.kover") version "0.6.1"
}

allprojects {
    apply(plugin = "kover")
}

subprojects {
    kover {
        engine.set(kotlinx.kover.api.DefaultJacocoEngine)
    }
}

kover {
    isDisabled.set(false)
    //engine.set(kotlinx.kover.api.JacocoEngine("0.8.8"))
    engine.set(kotlinx.kover.api.DefaultJacocoEngine)
}


koverMerged {
    enable()

    filters {
        classes {
            excludes.addAll(
                listOf(
                    "**/R.class",
                    "**/R$*.class",
                    "*Fragment",
                    "*Fragment\$*",
                    "*Activity",
                    "*Activity\$*",
                    "*Generated",
                    "**/BuildConfig.*",
                    "**/Manifest*.*",
                    "**/*Factory*",
                    "**/*_MembersInjector*",
                    "**android**",
                    "**/*Module*",
                    "**/*Component*",
                    "*.showkase.*",
                    "*.databinding.*", // ViewBinding
                    //"androidx.compose.runtime.Composable", // Composables
                )
            )
        }

        annotations {
            excludes.addAll(
                listOf(
                    "androidx.compose.runtime.Composable",
                    "com.company.android.core.navigation.NavGraphRoutes", // Jacoco was complaining about dupe classes
                    "io.realm.annotations.RealmModule" // Realm Modules
                )
            )
        }

        projects {
            excludes += listOf(
                //"domain",
            )
        }
    }

    xmlReport {
        onCheck.set(false)
        reportFile.set(layout.buildDirectory.file("$buildDir/reports/kover/result.xml"))
    }
    htmlReport {
        onCheck.set(false)
        reportDir.set(layout.buildDirectory.dir("$buildDir/reports/kover/html-result"))
    }
}

I had to add this to the app/build.gradle.kts in order to exclude certain flavors of tests, because there are about 7 build variants/flavors, and I only want to run tests for one.

android {
    testOptions {
        unitTests.all {
            println("DEBUG it.name=${it.name}")



            it.extensions.configure(kotlinx.kover.api.KoverTaskExtension::class) {
                isDisabled.set(!it.name.contains("testUsDebug"))

                println("kover isDisabled=${this.isDisabled.get()}")

                reportFile.set(file("$buildDir/custom/debug-report.bin"))

                includes.addAll(
                    listOf(
                        "com.company.*"
                    )
                )
            }
        }
    }

Reports
Screen Shot 2022-12-03 at 8 04 17 PM

Environment

  • Kover Gradle Plugin version: 0.6.1
  • Gradle version: 7.5.1
  • Kotlin project type: Kotlin/Multiplatform, Kotlin/Android (It is a mix)
  • Coverage Engine version: DefaultJacocoEngine

------------------------------------------------------------
Gradle 7.5.1
------------------------------------------------------------

Build time:   2022-08-05 21:17:56 UTC
Revision:     d1daa0cbf1a0103000b71484e1dbfe096e095918

Kotlin:       1.6.21
Groovy:       3.0.10
Ant:          Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM:          11.0.15 (Amazon.com Inc. 11.0.15+9-LTS)
OS:           Mac OS X 12.5 x86_64
@sonrohan sonrohan added Bug Bug issue type S: untriaged Status: issue reported but unprocessed labels Dec 4, 2022
@sonrohan
Copy link
Author

sonrohan commented Dec 4, 2022

Doing this is fine (with everything else above the same)

subprojects {
    kover {
        engine.set(kotlinx.kover.api.DefaultIntellijEngine)
    }
}

kover {
    isDisabled.set(false)
    //engine.set(kotlinx.kover.api.JacocoEngine("0.8.8"))
    engine.set(kotlinx.kover.api.DefaultIntellijEngine)
}

@sonrohan
Copy link
Author

sonrohan commented Dec 4, 2022

Screen Shot 2022-12-03 at 8 35 05 PM

This is all I see with debug logs

@shanshin
Copy link
Collaborator

shanshin commented Dec 5, 2022

Hi,
it may be related to #233.

May you try to force the Gradle to cache JaCoCo dependencies?
For example, by disabling Kover, and applying the jacoco plugin. After starting any JaCoCo task, it files will be downloaded and placed in the Gradle cache.

After that, you can repeat using the Kover plugin.

@shanshin shanshin added S: waiting for clarification Status: additional information required to proceed and removed S: untriaged Status: issue reported but unprocessed labels Dec 5, 2022
@sonrohan
Copy link
Author

sonrohan commented Dec 5, 2022

@shanshin It didn't seem to work, but one "hint"

I downgraded to 0.6.0, and when I run the report, I do atually get an error. The error is:

Caused by: java.io.IOException: Error while analyzing /Users/r.harrison/repos/cue-health-android/antiviral/build/intermediates/javac/qatarDebug/classes/com/company/android/antiviral/BuildConfig.class with JaCoCo 0.8.8.202204050719/5dcf34a.
        at org.jacoco.core.analysis.Analyzer.analyzerError(Analyzer.java:163)
        at org.jacoco.core.analysis.Analyzer.analyzeClass(Analyzer.java:135)
        at org.jacoco.core.analysis.Analyzer.analyzeClass(Analyzer.java:158)
        at org.jacoco.core.analysis.Analyzer.analyzeAll(Analyzer.java:195)
        at org.jacoco.core.analysis.Analyzer.analyzeAll(Analyzer.java:228)
        at org.jacoco.core.analysis.Analyzer.analyzeAll(Analyzer.java:223)
        at org.jacoco.core.analysis.Analyzer.analyzeAll(Analyzer.java:223)
        at org.jacoco.core.analysis.Analyzer.analyzeAll(Analyzer.java:223)
        at org.jacoco.core.analysis.Analyzer.analyzeAll(Analyzer.java:223)
        at org.jacoco.core.analysis.Analyzer.analyzeAll(Analyzer.java:223)
        at org.jacoco.ant.ReportTask.createBundle(ReportTask.java:570)
        at org.jacoco.ant.ReportTask.createReport(ReportTask.java:545)
        at org.jacoco.ant.ReportTask.execute(ReportTask.java:496)
        ... 143 more
Caused by: java.lang.IllegalStateException: Can't add different class with same name: com/company/android/antiviral/BuildConfig
        at org.jacoco.core.analysis.CoverageBuilder.visitCoverage(CoverageBuilder.java:106)
        at org.jacoco.core.analysis.Analyzer$1.visitEnd(Analyzer.java:100)
        at org.objectweb.asm.ClassVisitor.visitEnd(ClassVisitor.java:377)
        at org.jacoco.core.internal.flow.ClassProbesAdapter.visitEnd(ClassProbesAdapter.java:100)
        at org.objectweb.asm.ClassReader.accept(ClassReader.java:748)
        at org.objectweb.asm.ClassReader.accept(ClassReader.java:424)
        at org.jacoco.core.analysis.Analyzer.analyzeClass(Analyzer.java:117)
        at org.jacoco.core.analysis.Analyzer.analyzeClass(Analyzer.java:133)
        ... 154 more

I did try to exclude BuildConfig though using something like:

    koverMerged {
        filters {
            classes {
                excludes.addAll(
                    listOf(
                        "**/R.class",
                        "**/R$*.class",
                        "*Fragment",
                        "*Fragment\$*",
                        "*Activity",
                        "*Activity\$*",
                        "*Generated",
                        "*.BuildConfig.*",
                        "*BuildConfig\$*",
                        "**/BuildConfig.*",
                        "**/BuildConfig$*.class",
                        "**/BuildConfig.class",
                        "**/BuildConfig\$*.class",
                        "**/Manifest*.*",
                        "**/*Factory*",
                        "**/*_MembersInjector*",
                        "**android**",
                        "**/*Module*",
                        "**/*Component*",
                        "*.showkase.*",
                        "*.databinding.*", // ViewBinding
                        "**/*Companion*.*",
                        "**/*JsonAdapter.*",
                        "**/*$Result.*",
                        "**/*$Result$*.*",
                        //Copied from online
                    )
                )
            }

@shanshin
Copy link
Collaborator

shanshin commented Jan 6, 2023

Issue of stuck must be resolved with #284.
Issue Can't add different class with same name happens because Kover instrument all build types of the project, and if a class with the same name occurs in different build types/flavors, then Jacoco throws this error. Resolved in #18

@shanshin
Copy link
Collaborator

Fixed 0.7.0-Alpha

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Bug issue type S: waiting for clarification Status: additional information required to proceed
Projects
None yet
Development

No branches or pull requests

2 participants