简体   繁体   中英

'JacocoTaskExtension' does not exist with jdk11 , AGP 7.0.+ and ,Gradle 7.0.+

jacoco works like charm with AGP 4.0.1, gradle 6.+ , jdk1.8 but throw error "JacocoTaskExtension" not found with upgraded gradle version which is below.

   Gradle 7.0.2
------------------------------------------------------------

Build time:   2021-05-14 12:02:31 UTC
Revision:     1ef1b260d39daacbf9357f9d8594a8a743e2152e

Kotlin:       1.4.31
Groovy:       3.0.7
Ant:          Apache Ant(TM) version 1.10.9 compiled on September 27 2020
JVM:          11.0.12 (Oracle Corporation 11.0.12+8-LTS-237)
OS:           Mac OS X 11.5 x86_64

Steps to reproduce :

I am not able to import JacocoTaskExtension in below kotlin class CodeCoveragePlugin It's working fine with jkd 1.8 but not with jdk11

why am i using jdk11 ?

jdk11 is mandatory for agp 7.+ and gradle 7.+

My final goal : make it functional with agp7.+

package com.jitendra.sdk.android.gradle.quality.coverage

import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.plugins.JavaPlugin
import org.gradle.api.plugins.JavaPluginConvention
import org.gradle.api.tasks.testing.Test
import org.gradle.kotlin.dsl.*
import org.gradle.testing.jacoco.plugins.JacocoPluginExtension
import org.gradle.testing.jacoco.plugins.JacocoTaskExtension

@Suppress("UnstableApiUsage")
class CodeCoveragePlugin : Plugin<Project> {

    override fun apply(project: Project) = project.run {
        val extension = extensions.create("codeCoverage", CodeCoverageExtension::class)

        apply(plugin = "jacoco")

        jacoco {
            toolVersion = 0.8.7
        }
        java { createJavaTasks(sourceSets["main"], extension) }

        setupAndroidTasks(extension)
    }

    private fun Project.java(run: JavaPlugin.() -> Unit) = plugins.withType(JavaPlugin::class, run)

    private val Project.sourceSets get() = convention.getPlugin(JavaPluginConvention::class).sourceSets

    private fun Project.jacoco(run: JacocoPluginExtension.() -> Unit) = configure(run)
}

I have had a similar issue. Could you please check the listed stack trace from the console?

If it contains:

Unexpected SMAP line: *S KotlinDebug"

Then it's clear that you haven't used the correct version 0.8.7 of Jacoco, as discussed here . In my case, I still need to add the following configuration:

configurations.all {
        resolutionStrategy.eachDependency {
            if (requested.group == "org.jacoco") {
                useVersion("0.8.7")
            }
        }
    }

You can put it inside your project.run closure. Hope it works. If not, please share your stack trace as part of your question.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM