Search code examples
androidcode-coveragejacocospoon

Spoon and Jacoco with gradle


I used latest gradle version(3.3) and latest android gradle plugin(2.3.3) with latest jacoco version(0.7.7). I was able to get coverage reports and test results like a charm.

But the moment I added spoon plugin(I had not even applied spoon plugin but just added it to classpath in build script block) I started getting error with jacoco agent(java.lang.NoClassDefFoundError: org/jacoco/agent/rt/internal_b0d6a23/Offline). I saw multiple question about the error but none of the solutions work unless I used outdated versions of android gradle plugin and jacoco with spoon.

Please help if somebody has a real solution to the problem.


Solution

  • This error occurs if jacocoagent.jar has a different version of Jacoco than expected by plugin(in this case spoon plugin). org/jacoco/agent/rt/internal_b0d6a23/Offline has different names for internal_id/offline for different versions of jacoco. That is why error is there.

    If somebody else is getting this error, try running grade command from command line with --info flag and grep with "org/jacoco/agent/rt/internal_" to check which if there are different versions of Jacoco used.

    Then check different version of Jacoco in your gradle dependency graph to check which lib is causing problem.