I am currently using JaCoCo with Coveralls to integrate my (multi-module) project after the CI build so I might have slightly mistakes for a mono-module (I have adapted it) build but this is part of my research.
The first thing that you need to do is configure your build.gradle in order to have your tests working is applying the Jacoco plugin to your gradle:
apply plugin: "jacoco"
And then you have to enable the output:
jacocoTestReport {
group = "Report"
reports {
xml.enabled = true
csv.enabled = false
html.destination "${buildDir}/reports/coverage"
}
}
To generate the reports you can use: gradle test jacocoTestReport
(Feel free to add just a jacocoTestReport to your already working command to build)
After the reports are generated now you have to send them to coveralls, this is done in a step after the compilation/testing has finished.
To send it to coveralls you need to add the gradle plugin for coveralls:
plugins {
id 'com.github.kt3k.coveralls' version '2.7.1'
}
Create a rootReport task
task jacocoRootReport(type: org.gradle.testing.jacoco.tasks.JacocoReport) {
dependsOn = subprojects.test
sourceDirectories = files(subprojects.sourceSets.main.allSource.srcDirs)
classDirectories = files(subprojects.sourceSets.main.output)
executionData = files(subprojects.jacocoTestReport.executionData)
reports {
html.enabled = true
xml.enabled = true
csv.enabled = false
}
}
and add the kotlin sources for the coveralls task (only java support by default, Coveralls gradle plugin issue):
coveralls {
sourceDirs += ['src/main/kotlin']
}
I stumbled upon a bug when doing it that needed this three lines when generating the jacocoRootReport but this is mostly for a multi module project (workaround source):
onlyIf = {
true
}
The last step is configuring your CI tool to know where to find your coveralls token/properties (source). I personally have done it by adding environment variables and not coveralls.yml
(it didn't work well).
And now you can add two steps to your after build:
gradlew jacocoRootReport coveralls
And you should see your reports in your coveralls page!
Jacoco and coveralls: https://nofluffjuststuff.com/blog/andres_almiray/2014/07/gradle_glam_jacoco__coveralls
Working example: https://github.com/jdiazcano/cfg4k/blob/master/build.gradle#L24