Uploaded image for project: 'SonarJava'
  1. SonarJava
  2. SONARJAVA-2601

Add warning when information in JaCoCo exec-file doesn't match class files


    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 5.3
    • Component/s: JaCoCo
    • Labels:


      A frequent problem of JaCoCo users - are classes (or some of them) showing 0% coverage while they believe that classes were executed. In most cases this is caused by the fact that different classes are used at runtime (during execution of tests) and at analysis time (during generation of report) - for more information see http://www.jacoco.org/jacoco/trunk/doc/classids.html

      JaCoCo starting from version 0.6.5 provides API to detect such situation and tools are encouraged to use it to produce warning message as jacoco-maven-plugin, Ant Tasks and Gradle Plugin (Gradle actually uses Ant Tasks) - see https://github.com/jacoco/jacoco/pull/185

      # produce exec-file:
      $ mvn jacoco:prepare-agent test -Dmaven.compiler.target=1.5
      $ cp target/classes/Example.class .
      # produce different class file:
      $ rm -rf target/classes
      $ mvn compile -Dmaven.compiler.target=1.6
      $ diff Example.class target/classes/Example.class
      Binary files Example.class and target/classes/Example.class differ
      # warning during generation of report using jacoco-maven-plugin:
      $ mvn jacoco:report
      [WARNING] Classes in bundle 'example' do no match with execution data. For report generation the same class files must be used as at runtime.
      [WARNING] Execution data for class Example does not match.
      # no warning during SonarQube analysis:
      $ mvn sonar:sonar -X
      [DEBUG] 22:21:21.847 Plugins:
      [DEBUG] 22:21:21.847   * SonarJava (java)
      [INFO] 22:21:27.091 Sensor JaCoCoSensor [java]
      [INFO] 22:21:27.097 Analysing /private/tmp/j/target/jacoco.exec
      [INFO] 22:21:27.159 No information about coverage per test.
      [INFO] 22:21:27.159 Sensor JaCoCoSensor [java] (done) | time=68ms

      Currently such mismatch is hard to diagnose during import of exec-file into SonarQube and SonarQube users are not necessarily use or try to use other tools for generation of report - see for example https://github.com/eclipse/eclipse.jdt.ls/issues/382

      Therefore I propose to add warning.




            • Assignee:
              michael.gumowski Michael Gumowski
              evgeny.mandrikov Evgeny Mandrikov
            • Votes:
              0 Vote for this issue
              2 Start watching this issue


              • Due: