Skip to content

Instantly share code, notes, and snippets.

@goofyahead
Created June 26, 2018 09:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goofyahead/73c6cca0ec76dc9bff7ccb88dea9ce2d to your computer and use it in GitHub Desktop.
Save goofyahead/73c6cca0ec76dc9bff7ccb88dea9ce2d to your computer and use it in GitHub Desktop.
jacoco report for android projects
apply plugin: 'org.sonarqube'
apply plugin: 'jacoco'
def androidExclusion = [
'**/databinding/**/*.*',
'**/android/databinding/*Binding.*',
'**/BR.*',
'**/R.*',
'**/R$*.*',
'**/BuildConfig.*',
'**/Manifest*.*',
'**/*_MembersInjector.*',
'**/Dagger*Component.*',
'**/Dagger*Component$Builder.*',
'**/*Module_*Factory.*',
'**/*Fragment*.*',
'**/*Activity*.*',
'**/*Adapter*.*',
'**/*ViewPager*.*',
'**/*ViewHolder*.*',
'**/*Module*.*'
]
sonarqube {
properties {
property "sonar.host.url", "http://localhost:9000/"
property "sonar.sourceEncoding", "UTF-8"
property "sonar.projectKey", "myProject"
property "sonar.projectName", "myProject"
property "sonar.projectVersion", "V1.0"
property "sonar.sources", "src/main/java"
property "sonar.tests", ["src/test/java", "src/test/kotlin"]
property "sonar.java.coveragePlugin", "jacoco"
property "sonar.coverage.exclusions", "${androidExclusion.join(',')}"
property "sonar.jacoco.reportPaths", "${project.buildDir}/jacoco/testStagingDebugUnitTest.exec"
property "sonar.junit.reportsPath", "${project.buildDir}/test-results/testStagingDebugUnitTest"
}
}
task codeCoverageReport(type: JacocoReport, dependsOn: 'testStagingDebugUnitTest') {
group = "Reporting"
description = "Generate Jacoco coverage reports after running tests."
reports {
xml.enabled = true
html.enabled = true
}
classDirectories = fileTree(
dir: 'build/intermediates/classes/staging/debug/com/yourpackage',
excludes: androidExclusion
)
sourceDirectories = files('src/main/java/yourpackage')
executionData = files('build/jacoco/testStagingDebugUnitTest.exec')
}
task getSkywardsCoverage(type: Exec, dependsOn: 'codeCoverageReport') {
group = "Reporting"
commandLine "open", "$buildDir/reports/jacoco/codeCoverageReport/html/index.html"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment