Below is the steps that I had followed:
1. placed the org.jacoco.agent-0.8.2-runtime.jar in my local machine. Created a simple java class with just one function.
2. Added the BDD feature file and the step definition file so that Step definition file calls the function defined in the java class created in step1.
Added the agent to JVM option of the cucumber runner configuration, refer the screen shot below:
Execute the BDD tests. the .exec file is generated.
using the .exec file, a gradle task was added in the build.gradle to generate the report. below are the details of the dependencies wihch i added in my build.gradle file.apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'jacoco'
jacoco {
toolVersion = "0.8.2"
reportsDir = file("$buildDir/jacocoHtml")
}
dependencies {
testCompile(group: 'org.jacoco', name: 'org.jacoco.agent', version: '0.8.2', classifier: 'runtime')
}
dependencies {
testCompile 'info.cukes:cucumber-java:1.2.5'
testCompile 'info.cukes:cucumber-jvm:1.2.5'
testCompile 'info.cukes:cucumber-jvm-deps:1.0.5'
testCompile 'info.cukes:cucumber-junit:1.2.5'
testCompile 'info.cukes:cucumber-core:1.2.5'
testCompile 'info.cukes:gherkin:2.12.2'
testCompile 'net.masterthought:cucumber-reporting:3.8.0'
testCompile 'com.github.mkolisnyk:cucumber-reports:1.2'
testCompile 'com.jayway.restassured:rest-assured:2.7.0'
testCompile 'com.opencsv:opencsv:4.0'
testCompile 'org.hamcrest:hamcrest-library:1.1'
}
task generateJacocoUTReport(type: JacocoReport, group: "jacocotest") {
dependsOn allprojects.test
additionalSourceDirs = files(subprojects.sourceSets.main.allSource.srcDirs)
sourceDirectories = files(subprojects.sourceSets.main.allSource.srcDirs)
classDirectories = files(subprojects.sourceSets.main.output)
executionData file("$buildDir/bddTest.exec")
reports {
xml.enabled = false
csv.enabled = false
html.destination file("$buildDir/jacoco/html")
}

additionalSourceDirs = files(subprojects.sourceSets.main.allSource.srcDirs)
println additionalSourceDirs.size()
println additionalSourceDirs.empty
sourceDirectories = files(subprojects.sourceSets.main.allSource.srcDirs)
println sourceDirectories.size()
println sourceDirectories.empty
classDirectories = files(subprojects.sourceSets.main.output)
println classDirectories.empty
println classDirectories.files
def execfile= executionData file("$buildDir/jacoco/bddTest.exec")
println execfile
println "$buildDir/jacoco/bddTest.exec"
additionalSourceDirs = files(sourceSets.main.allSource.srcDirs)
sourceDirectories = files(sourceSets.main.allSource.srcDirs)classDirectories = files(sourceSets.main.output)