java.lang.ClassNotFoundException: org.jacoco.ant.MergeTask

Hi,

I have an Android project with gradle 2.14.1 and want to set up jacoco integration. For the part invoking jacocoTestReport, it works. However, when it comes to jacocoMerge it starts to throw classNotFoundException.

apply plugin: 'jacoco'

task merge(type: JacocoMerge) {
    group = "Reporting"
    description = "Generate Jacoco coverage reports after other individual jacoco tests."

    destinationFile = file("$buildDir/jacoco/jacocoLibSummary.exec")
    executionData = files()
    jacocoClasspath = files()
}

./gradlew tasks works, and shows merge task.
but if I want to invoke merge task, it has the following error:

$ ./gradlew merge
To honour the JVM settings for this build a new JVM will be forked. Please consider using the daemon: https://docs.gradle.org/2.14.1/userguide/gradle_daemon.html.
Incremental java compilation is an incubating feature.
:merge FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':merge'.
> java.lang.ClassNotFoundException: org.jacoco.ant.MergeTask
...

According to https://docs.gradle.org/2.14/userguide/jacoco_plugin.html, jacoco plugin should pull in JacocoAnt as well, so I was wondering what part I could be missing.

I’ve tried adding the following, but still no luck.

buildscript{
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'org.jacoco:org.jacoco.ant:0.7.8'
    }
}

Edit: upgraded the dummy project to gradle 3.3, and same issue.

Fixed it using the following

build.gradle on plugin project


dependencies {
    compile gradleApi()
    compile localGroovy()

    compile "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.6.2"
    compile 'org.jacoco:org.jacoco.ant:0.7.8'
}

jacoco merge task


        project.task('jacocoMerge', type: JacocoMerge.class) { JacocoMerge m ->

            m.dependsOn project.allprojects.collect { it.tasks.withType(JacocoReport.class) }
            m.destinationFile = project.file(mergedCoverage)

            //Not all test projects will have a jacoco report so they need to be manually filtered out
            //Otherwise the merge will blow up.
            m.doFirst {
                m.executionData = project.files(m.executionData.findAll { x -> x.exists() })
            }

            project.allprojects.each { Project s ->
                m.executionData s.tasks.withType(Test.class)
            }

            m.jacocoClasspath = project.buildscript.configurations.classpath
        }