Exclude Packages from Jacoco Report Using Sonarrunner and Gradle

Is there a way to exclude packages from SonarQube(instrumented by gradle + sonar-runner) coverage reports(generated by jacoco) without excluding them completely from the project ?

Below is what i tried so far:

Version information

  • SonarQube 4.5.1
  • Gradle 2.2.

Jacoco configuration

// JaCoCo test coverage configuration
tasks.withType(Test) { task ->
    jacoco {
        append = false

        // excluded classes from coverage defined in above configuration
        excludes = excludedClasses()
    }

    jacocoTestReport {
        doFirst {
            classDirectories = fileTree(dir: "${buildDir}/classes/main/").exclude(excludedClasses())
        }
    }

}
Sarah Jenkins

Sarah Jenkins

Senior Technology Editor & AI Specialist

Sarah Jenkins is a veteran tech journalist with over 12 years of experience covering artificial intelligence, mobile innovations, and digital ethics. Her insights have appeared in leading technology publications worldwide.