From jacoco (0.7.8) doc " If classes get modified at runtime in your setup there are some workarounds to make JaCoCo work anyways: If you use another Java agent make sure the JaCoCo agent is specified at first in the command line. This way the JaCoCo agent should see the original class files.
Specify the classdumpdir option of the JaCoCo agent and use the dumped classes at report generation. Note that only loaded classes will be dumped, i.e. classes not executed at all will not show-up in your report as not covered. Use offline instrumentation before you run your tests. This way classes get instrumented by JaCoCo before any runtime modification can take place. Note that in this case the report has to be generated with the original classes, not with instrumented ones."
I am using ""Specify the classdumpdir option... " How to use dumped classes for report?
Three problems in doing this (1) 'classDumpDir'/'classDumpDir' of prepare-agent does include this in javaagent, but report goal is unaware of this and (2) report goal has no way of configuring this (3) I know using default might be the best bet, but whats the default location for dumped classes where report looks?
I instrument offline and run the testes by amending pom.xml, all runs fine and report shows up. But if I try to do the same through commandline (really helpful for massive projects wehre pom structures are huge and complex) it fails, I run the same phases/goals howerever. Following are mvn commands I am trying and their outcome.
clean org.jacoco:jacoco-maven-plugin:prepare-agent test org.jacoco:jacoco-maven-plugin:report -- Coverage for classes using powermock doesnt showup obviously, class file looked at during report generation are different. If the concept of classdumpdir works, we should be able to use this command itself without the need for offline instrumentation (I guess).
org.jacoco:jacoco-maven-plugin:prepare-agent org.jacoco:jacoco-maven-plugin:instrument test org.jacoco:jacoco-maven-plugin:restore-instrumented-classes org.jacoco:jacoco-maven-plugin:report --- Again in principle this should work, but I get the same error as above that the class execution data doesnt match?
mvn clean -Djacoco.classDumpDir=${project.build.directory}/classDumpDir org.jacoco:jacoco-maven-plugin:prepare-agent org.jacoco:jacoco-maven-plugin:instrument test org.jacoco:jacoco-maven-plugin:restore-instrumented-classes org.jacoco:jacoco-maven-plugin:report -- I am trying to combine both by instrumenting and using the instrumented class before test for report, not sure how to instruct report to look at them. Its not possible to copy classes from classdumpdir into target/classes because the former doesnt has class files of the original classes (ie the classes under test).
Please let me know if you are aware of any other means of getting this to work. Thanks again!
clean compile org.jacoco:jacoco-maven-plugin:instrument test org.jacoco:jacoco-maven-plugin:restore-instrumented-classes org.jacoco:jacoco-maven-plugin:report
'Instrument' is executed as part of maven 'process-classes' which comes after 'compile', but for some reason code was not getting compiled and hence 'classes' folder was not found so obviously jacoco was not generating report. Now when I manually compile, it is working fine. Down side is it tries to compile twice, once before instrument and once after instrument, but since the source is already compiled, the second compile doesnt do anyting, it just posts tht 'no change in class'.