How do you configure the jacoco plugin to perform offline instrumentation so that powermock does not report 0% coverage on all the classes?

I am trying to use the jacoco plugin and somehow setup the build so that when I run the unit tests the classes are already instrumented when powermock goes to do its thing, otherwise powermock instruments the classes and jacoco cannot find any of them because they no longer match, so all classes show 0% coverage.

It seems like this must be possible but cannot find a working example.


JaCoCo instruments classes as they get loaded by the JVM. I don’t think it supports instrumenting classes offline.

JaCoCo supports offline instrumentation.

Maybe the gradle plugin does not, but not sure. It does use the ant stuff under the hood so I figured maybe it does do it but just isn’t documented.

OK, good to know. Then it’s indeed a limitation of Gradle’s JaCoCo plugin.

Not super familiar with gradle yet, more used to maven, but I might be able to extend the plugin to support this since it already uses the ant stuff. If not, then a custom ant based task. It doesn’t look too complicated just reading about how to use ant from gradle.