Display test coverage with jacoco in gradle

I am using gradle file to build my project. In this file, I am using jacoco to generate a test report. What I want to do is change the build file so that it displays a message if my test coverage is not 100%. Or at least just display the test coverage. Is it possible?

Here is my build.gradle:

apply plugin: 'java'
apply plugin: 'jacoco'

sourceSets.main.java.srcDirs = ['src']
sourceSets.test.java.srcDirs = ['test']

dependencies {
    testCompile group: 'junit', name: 'junit', version: "4.+"
}

repositories {
    mavenCentral()
}

jacocoTestReport {
    doFirst {
      classDirectories = files('build/classes/main/draw')
    }
    reports {
        xml.enabled false
        csv.enabled false
        html.destination "build/reports/coverageHtml"
    }
}

task(runui, dependsOn: jar, type: JavaExec) {

    main = 'gui.Main'
    classpath = sourceSets.main.runtimeClasspath
}

defaultTasks 'clean', 'test', 'jacocoTestReport', 'runui'

      

+3


source to share


1 answer


This is currently not supported by the jacoco gradle plugin. You can vote for this issue at https://issues.gradle.org/browse/GRADLE-2783 and https://issues.gradle.org/browse/GRADLE-2854 . As a workaround, you can parse the output file in a custom task.



+1


source







All Articles