Found answer to my 2nd question. High level info:
Gradle 1.6 jacocoTestReport uses different variables, Gradle >=1.7 uses different.
For ex: we can tweak Unit tests and Integration Tests .exec file creation by changing "test" or "integrationTest" task by using the CORRECT variables -or it wont work n generate "test.exec" and "integrationTest.exec" default file names. See example below.
task integrationTest(type: Test) OR test { ... } section can have the correct variables for the given Gradle version that we are using.
task integrationTest (type: Test) {
testClassesDir = sourceSets.integrationTest.output.classesDir
classpath = sourceSets.integrationTest.runtimeClasspath
testReportDir = file("$buildDir/reports/tests/IT")
testResultsDir = file("$buildDir/test-results/IT")
ignoreFailures = true
jacoco {
//This works with 1.6
destPath = file("$buildDir/jacoco/IT/jacocoIT.exec")
classDumpPath = file("$buildDir/jacoco/IT/classpathdumps")
/*
Following works only with versions >= 1.7 version of Gradle
destinationFile = file("$buildDir/jacoco/IT/jacocoIT.exec")
classDumpFile = file("$buildDir/jacoco/IT/classpathdumps")
*/
}
}
Similarly, for test { .... } task, you can define it as ../../UT/jacocoUT.exec and ../../UT/classpathdumps...
.sonar folder gets created if I run "sonar-runner" Linux/Unix sonar-runner executable in my project's workspace, BUT if I run Jenkins job which calls Gradle "clean build integrationTest jacocoTestReport sonarRunner", then build/sonar folder is created and becomes the WORKING DIR for SONAR (this shows up during the output).
In Jenkins > under Post build section, I mentioned the following and NOW, jacoco code coverage report on Jenkins Dashboard for both jacoco files (.html and .xml) - includes Unit and Integration tests code coverage data.
Record Jacoco coverage report section in Jenkins has the following boxes:
I mentioned:
Path to exec files: /build/jacoco/UT/jacocoUT.exec, */build/jacoco/IT/jacocoIT.exec
Path to class dirs: */build/jacoco//classpathdumps/com/thc
(this is the location where Jacoco instrumented classes sit).. both build/jacoco/UT/classpathdumps/com/thc and build/jacoco/IT/classpathdumps/com/thc will be picked as ** will be replaced for any folder under build/jacoco. this value can be set to "build/classes" folder as well.
Path to source files: **
(if I use src/java, few of the links for source file don't work i.e. file contents don't show up).. used ** .. it works now.
rest boxes - left blank.
- Still wondering - why overall-jacoco.exec is not having the file size = sum of both jacocoUT.exec and jacocoIT.exec
At this point, I'm able to see Jacoco code coverage for both Unit and Integration Tests i.e. via visiting the Jacoco code coverage image on job's dashboard and visiting source code links and also if you go and browse "build/reports/jacoco/html/index.html" or "build/jacocoHtml/index.html" file.
Still trying to find out - what needs to be done for SONAR to pick these 2 .exec files (I have valid values set for sonar.xxx variurs variables for sources, tests, binaries, ...reportsPath etc for UT / IT exec files... on SonarQube dashboard, Unit test coverage is showing up fine but Integration tests coverage is still 0.0%.
I'll paste the copy of both my common.gradle and project's build.gradle file soon .... to have a better look.