Update: I know why! -- sourceSet { ... } section for main/java, test/java, etc.. has a 'not_valid_value' for srcDir setting for each main, test, etc section --> in my global init.d level "common.gradle" file and it's applied to allprojects {...}. I have mentioned global sourceSet section in global common.gradle file so that I dont have to include common tasks/configurations for test, integrationTest etc tasks in each project's build.gradle file. Now, because srcDir for each of them is set to 'not_valid_value' at global level, my assumption is, this invalid srcDir value will be either overwritten by the actual valid srcDir value (when Gradle build system will read sourceSets section {...} from each individual project's build.gradle file's sourceSet section for main, test, etc OR they will be clubbed together as a list entry i.e. main srcDir will become ['src/java', 'not_valid_value'] --- which when I printed in common.gradle and ran project gradle build, printed valid clubbed value:
println ""
println "sourceSets.main.allJava.srcDirs is set to : " + sourceSets.main.allJava.srcDirs
println ""
value printed, don't know if ' quotes will be required as Gradle printed it fine:
sourceSets.main.allJava.srcDirs is set to : [/production/jenkinsAKS/workspace/MFUSvc/src/main/java, /production/jenkinsAKS/workspace/MFUSvc/not_valid_value]
Thus, when I'm using, sourceSets.main.allJava.srcDirs for sourceDirectories variable in jacocoTestReport task, its passing and not giving me an error (as I have mentioned in my post) even though, srcDir variable for main/java is: ['src/java', 'not_valid_value'] at BUILD TIME i.e. one from common.gradle and one from project's build.gradle sourceSet section. I don't get the error NOW, BUT it's now breaking the HTML links in generated reports aka index.html... see below snapshot image.
When I use the actual value for main/java, test/java (i.e. srcDir 'src/java' or srcDir 'test/java' or srcDir 'src/java-test') in "common.gradle" global file, inside sourceSet section --OR if I hard code sourceDirectories variable of jacocoTestReport task ---- it's giving me the same error that I have mentioned in the post BUT for other projects, its successful and I see HTML links are working in jacoco HTML report index.html. Wherever it's successful in this case, I found that I had valid source code java file under test/java or src/java-test tree. The project which is failing and giving me an error doesn't have anything under test/java, src/java-test tree thus, during the build, build/jacoco folder is not generated as no tests are there for the project which is failing. So, it still remains, why "src/java" or "src/java-test" is failing jacocoTestReport task for this particular project.
If I use the following inplace of defining actual value src/java
sourceDirectories = files(sourceSets.main.allJava.srcDirs)
for JacocoTestReport task, it works for showing the coverage % info correctly and the error messages shown in my post above are NOT showing up now (may be srcDir is not valid value -- but I printed the value of sourceSets.main.allJava.srcDirs and it shows ['src/java', 'not_valid_value'] at build time), but it breaks the HTML links to the source file i.e. when you browse jacoco HTML report Element column, you can see coverage percentage but at the deep end, when you click at the function/class level, you can't see the source code of the file (where you can see Green/Yellow/Red coverage by line).
If I'm using "src/java" in sourceSets { .. main { java { srcDir 'src/java' } } } OR for sourceDirectories = files('src,java') in jacocoTestReport task ---> then I'm getting the following error:
Caused by: java.io.FileNotFoundException: /production/jenkinsAKS/workspace/MFUSvc/src/java/com/thc/ids/biz/mfusvc/dto (Is a directory)
I see the other similar error message with path "src/java-test" in it as the source control does have src/java-test containing tests.
//The following works for showing coverage %, but can't see file content at func/class level in HTML report
sourceDirectories = files(sourceSets.main.allJava.srcDirs)
// Enabling/uncommenting The following line for sourceDirectories - shows both coverage % and at the deep level if you click func/class Element link in jacoco HTML report, you'll see file content with colored coverage per line BUT, it gives error in few projects not in all (as for some, jacocoTestReport is successful)
//sourceDirectories = files('src/java')
//classDirectories = files('build/classes/main')
//------------------------------------------
// If I play with uncommenting the following, I see that jacocoTestReport task generating (is a directory) error message either for src/java-test or test/java -- in some projects.. NOTE: not in all projects.
//additionalSourceDirs = files('test/java')
//additionalSourceDirs += files('src/java-test')
//additionalClassDirs = files('build/classes/test')
//additionalClassDirs += files('build/classes/integrationTest')
//additionalClassDirs += files('build/classes/acceptanceTest')
//------------------------------------------
ATLEAST, one thing is clear for which I was looking for some time now. "Element" column link for function or class level is working when I'm giving hard coded value. Somehow it's not picking (sourceSets.main.allJava.srcDirs) or (sourceSets.main.java.srcDirs) which is what I saw in some blogs.