Repository: Kotlin/kotlinx-kover

Issue #362: applicationVariants/libraryVariants are eagerly evaluated and result in missed test data
Created: 2023-05-04T19:32:16Z
Describe the bug
This code eagerly evaluates applicationVariants/libraryVariants in Android projects, and the result is that they have empty variants if the plugin is applied before the android variants are set up and the kover report task will be skipped due to no inputs.

  
    
      kotlinx-kover/src/main/kotlin/kotlinx/kover/gradle/plugin/locators/Android.kt
    
    
        Lines 28 to 32
      in
      9c36932
    
  
  
    

        
          
           val variants = if ("applicationVariants" in androidExtension) { 
        

        
          
               androidExtension.propertyBeans("applicationVariants") 
        

        
          
           } else { 
        

        
          
               androidExtension.propertyBeans("libraryVariants") 
        

        
          
           } 
        
    
  


Errors
If present, stacktraces or files from build/kover/errors directory
Expected behavior
This API is old and the wrong API to use. Instead, the new androidComponents.onVariants API should be used, as this is a push system that will callback with each variant. This API is present in AGP 7.0 and later.
Reproducer
Easy to reproduce in a project that applies the kover plugin before configuring android variants.
Reports
If applicable, report files or screenshots.
Environment

Kover Gradle Plugin version: 0.7.0-Beta
Gradle version: 8.0.2/8.1.1
Kotlin project type: Kotlin/Android
Coverage Engine version (if customized in build script): N/A
Other context important for this bug: [e.g. OS version]

Duplicate issue #364: Task 'koverXmlReport' will be skipped because no tests were executed in Android project on 0.7.0
Created: 2023-05-09T14:56:45Z
Describe the bug
A report is not generated for Android modules on version 0.7.0-Beta. But successfully generates on 0.6.1
Note: a report generates for non-android modules successfully.
// given

android module on non-multiplatform, but multimodule Android project.
unit tests exist in the Android module

// when

:my_module:koverHtmlReport

// then

I see the error Task 'koverXmlReport' will be skipped because no tests were executed

if I run ./gradlew my_module:tasks I'll see

Expected behavior
Report generated
Reproducer
build.gradle of my_module
plugins {
    id 'com.android.library'
    id 'kotlin-android'
    id 'org.jetbrains.kotlinx.kover'
}

android {
    compileSdkVersion COMPILE_SDK_VERSION

    defaultConfig {
        minSdkVersion MIN_SDK_VERSION
        targetSdkVersion COMPILE_SDK_VERSION

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
       
    }

    buildTypes {
        debug {
            testCoverageEnabled true
        }
        release {
            ...
        }
    }

    composeOptions {
        ...
    }
    buildFeatures {
        compose true
    }
    packagingOptions {
        ...
    }
}

dependencies {
    ...
}

Reports
If applicable, report files or screenshots.
Environment

Kover Gradle Plugin version: [e.g. 0.7.0-Beta]
Gradle version: gradle-7.6-all
Kotlin project type: [Kotlin/Android]
Coverage Engine version: default
Other context important for this bug: [e.g. OS version] works fine on 0.6.1

Closing comment (2023-05-16T13:11:16Z): So, I should use only plugins for applying kover plugin.

allprojects { ... } should also work. I think it's related to #362.
I'm closing this task as a duplicate, but after fixing #362, it would be useful to recheck your project