Jacoco not doing full code coverage

852 views
Skip to first unread message

prateek gupta

unread,
Jul 14, 2017, 7:03:00 AM7/14/17
to JaCoCo and EclEmma Users
I am trying to generate coverage report using jacoco but unable to do so because of following error :

[ant:jacocoReport] Classes in bundle 'pubmindApp' do no match with execution data. For report generation the same class files must be used as at runtime.

Below is my current build gradle :

configurations {
    agentlib
}
ext{
isBuildMaster = true
jacocoversion = '0.7.6.201602180812'
}
if (hasProperty('extraChecks') || isBuildMaster == true) {
  jacocoTestReport {
   def coverageSourceDirs = ['src/main/java']
    reports {
        xml.enabled true
        html.enabled true
        csv.enabled false
    }
    sourceDirectories = files(coverageSourceDirs)
  }
  build.dependsOn(jacocoTestReport)
}

jacoco {
toolVersion = jacocoversion
}

test {
jacoco {
            destinationFile = file("$buildDir/jacoco/test.exec")
            classDumpFile = file("$buildDir/jacoco/classpathdumps")
    }
    ext.agentlibs = configurations.agentlib.collect {it}
    ext.springInstrument = agentlibs[0]
    // Uncomment the following line to see the test output on console 
    //testLogging.showStandardStreams = true
    println("springframework instrument path: $springInstrument")
    jvmArgs "-Xms256m"
    jvmArgs "-Xmx4096m"
    jvmArgs "-XX:MaxPermSize=256m"
    jvmArgs "-Djava.library.path=${root}/java/lib:${service_root}/home/tivo/lib"
    jvmArgs "-javaagent:$springInstrument"
    include "**/Test*.class"
    exclude 'com/tivo/service/pubmind/trio/TestVodCategoryOperation.class'
   exclude 'com/tivo/service/pubmind/trio/TestVodCatalogOperation.class'
    environment('SERVICE_ROOT', service_root);
    environment('SRCROOT', srcroot);
    doFirst {
      if(System.getProperty('extraTests') == '1'){ 
        include "**/ExtraTest*.class"
        println "Include  extra tests";
      } else {
        println "Skipping extra test, extraTests not enabled";
      }
   }
}

test.finalizedBy jacocoTestReport

I have tried using offline instrumentation, creating classdump but still the same error keeps on popping up. Please help out

Evgeny Mandrikov

unread,
Jul 17, 2017, 9:00:52 PM7/17/17
to JaCoCo and EclEmma Users
According to line

jvmArgs "-javaagent:$springInstrument"

you use another agent that I assume also performs bytecode transformations. Please make sure that JaCoCo agent is listed first in the command line before any other agents, so that it will see unmodified classes.

Also should be noted that seems that Gradle JaCoCo Plugin does not enforce this automatically, so please report this to Gradle, who develops the plugin.

Offline instrumentation as well as mismatch of classes are described in documentation and there are plenty of topics in mailing list about this ( e.g. https://groups.google.com/d/msg/jacoco/5IqM4AibmT8/-x5w4kU9BAAJ ) as well as in internet. There is nothing to add to all this without having an ability to reproduce your difficulty with proper configuration.

prateek gupta

unread,
Jul 18, 2017, 1:08:08 AM7/18/17
to JaCoCo and EclEmma Users
I have tried putting my jacocoagent before spring instrument agent but that as well did not help. I started getting error on gradle classes stating these classes are already instrumented.

java.lang.instrument.IllegalClassFormatException: Error while instrumenting class jarjar/org/gradle/process/internal/launcher/GradleWorkerMain.
> Buildiat org.jacoco.agent.rt.internal_14f7ee5.CoverageTransformer.transform(CoverageTransformer.java:93)
        at sun.instrument.TransformerManager.transform(TransformerManager.java:169)
        at sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:365)
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
        at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Caused by: java.io.IOException: Error while instrumenting class jarjar/org/gradle/process/internal/launcher/GradleWorkerMain.
        at org.jacoco.agent.rt.internal_14f7ee5.core.instr.Instrumenter.instrumentError(Instrumenter.java:152)
        at org.jacoco.agent.rt.internal_14f7ee5.core.instr.Instrumenter.instrument(Instrumenter.java:103)
        at org.jacoco.agent.rt.internal_14f7ee5.CoverageTransformer.transform(CoverageTransformer.java:91)
        ... 14 more
Caused by: java.lang.IllegalStateException: Class jarjar/org/gradle/process/internal/launcher/GradleWorkerMain is already instrumented.

once after finishing that (if i ignore these errors), I am still getting errors in execution data mismatch. I have tried offline instrumentation as well but did not help.

Evgeny Mandrikov

unread,
Jul 18, 2017, 5:07:23 AM7/18/17
to JaCoCo and EclEmma Users
Let me repeat: please make sure to provide fully complete and runable example demonstrating your difficulty with configuration. We are not gonna guess your configuration our of infinite number of possibilities.

Evgeny Mandrikov

unread,
Jul 18, 2017, 6:42:00 AM7/18/17
to JaCoCo and EclEmma Users
In addition - incredibly basic things:

"Class ... is already instrumented." do not mix offline instrumentation with on-the-fly, do not perform offline instrumentation twice (in particular - do "gradle clean" to remove results of past incorrect attempts), etc, etc, etc

Do not ignore exceptions, do not focus on "class does not match" - it is pointless to talk about correctness of final result as long as you have exceptions on early stages.
Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages