10

Info: java version: 1.8.0_66 ant version: 1.9.6

What I want to do:

Provide a code coverage report for the server's code that is running on AWS windows 2k12 server.

What I did:

  • Stop the server completely.
  • Put jacocoagent.jar into server's bin folder. Note: this is inside Program Files folder
  • Append -javaagent settings to JAVA_OPTS that is used during server start up.
  • Start the server.
  • Run my sample test from my local laptop.
  • Stop the server completely. This produced a 184kb jacoco.exec.
  • Copied my build.xml to the same directory where the jacoco.exec is located. C:/path/to/exec/jacoco.exec
  • Copied jacocoant.jar to C:/path/to/jacocoant.jar
  • cd into C:/path/to/exec/ and run command "ant"

Result:

Got error unable to read execution data file C:/path/to/exec/jacoco.exec

Build.xml:

<project name="Example" default="rebuild" xmlns:jacoco="antlib:org.jacoco.ant">

<description>
  Example Ant build file that demonstrates how a JaCoCo coverage report
  can be itegrated into an existing build in three simple steps.
</description>

<property name="result.dir" location="." />
<property name="result.classes.dir" location="${result.dir}/path/to/classes" />
<property name="result.report.dir" location="${result.dir}/report" />
<property name="result.exec.file" location="${result.dir}/jacoco.exec" />

<!-- Step 1: Import JaCoCo Ant tasks -->
<taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
    <classpath path="../jacocoant.jar" />
</taskdef>

<target name="clean">
    <delete dir="${result.report.dir}" />
</target>

<target name="report">
    <!-- Step 3: Create coverage report -->
    <jacoco:report>

        <!-- This task needs the collected execution data and ... -->
        <executiondata>
            <file file="${result.exec.file}" />
        </executiondata>

        <!-- the class files and optional source files ... -->
        <structure name="JaCoCo Code Coverage Report">
            <classfiles>
                <fileset dir="${result.classes.dir}" >
                    </fileset>
            </classfiles>
            <sourcefiles encoding="UTF-8">
                <fileset dir="${src.dir}" />
            </sourcefiles>
        </structure>

        <!-- to produce reports in different formats. -->
        <html destdir="${result.report.dir}" />
        <csv destfile="${result.report.dir}/report.csv" />
        <xml destfile="${result.report.dir}/report.xml" />
    </jacoco:report>
</target>

I am not sure if the problem is with exec file (it is corrupted maybe) or is with my entire setup. Any help to identify and help solving the problem is appreciated!!!

Thanks!

DMeng
  • 143
  • 1
  • 2
  • 7

3 Answers3

6

I got this when using gradle and jaCoCo.

I deleted the build/ directory and reran ./gradlew jacocoTestReport, this time passing.

noqcks
  • 513
  • 5
  • 9
2

I have the same problem recently, it took me long time to figure this out. I hope how I fix this will help you or someone else.

  1. Use ant -verbose report to see the detailed information. I used "ant -verbose report" and got this message: "java.io.IOException: Incompatible version 1007".
  2. As I am using maven, I added the following lines to my pom.xml. Note: version is the same as your javaagent's version.

<dependency> <groupId>org.jacoco</groupId> <artifactId>org.jacoco.ant</artifactId> <version>0.7.4.201502262128</version> </dependency>

In the end, the report is successfully generated.

srk
  • 4,857
  • 12
  • 65
  • 109
sofia
  • 763
  • 8
  • 11
2

Similar to @sofia's solution but for gradle: I removed the version after tool version. Instead of

allprojects {
    jacoco {
        toolVersion = '0.7.1.201405082137'
    }
}

I used the following

allprojects {
    jacoco {
        toolVersion = '0.7.1'
    }
}
Josh Wang
  • 521
  • 7
  • 17