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!

1
  • Did you find the answer? Commented Apr 20, 2016 at 14:29

3 Answers 3

6

I got this when using gradle and jaCoCo.

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

Sign up to request clarification or add additional context in comments.

Comments

3

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.

Comments

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'
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.