2

I am new to JaCoCo and trying to figure out why the html report that I am generating is not linked with my source.

The coverage numbers look correct and I can browse down to each class and then each method but I can not see the source. I have tried many different things inside the sourcefiles tag but nothing is working. Has anyone else had this issue? Here is a snippet of my ant script:

...

   <test name="test.fw.UITestSuite" todir="${logdir}"/>
    </junit>
    </jacoco:coverage>
    <fail if="TestFailed" status="1" message="UI junit test failure detected"/>
    <echo message="${src}"/>
    <jacoco:report>                                
        <executiondata>
            <file file="jacoco.exec"/>
        </executiondata>                            
        <structure name="UI">
            <classfiles>
                <fileset dir="${build}/fw"/>
            </classfiles>
            <sourcefiles encoding="UTF-8">
                <fileset dir="fw" includes="**./*.java"/>
            </sourcefiles>
        </structure>                                
        <html destdir="report"/>                                
    </jacoco:report>
</target>

...

2 Answers 2

1

Your fileset definition seems odd.

The include must be (the first . is misplaced):

includes="**/*.java

Try simply pointing it to the root of your src dir (there is no need for the includes)

<fileset dir="fw"  />

But fw has to be the root of your sources, i.e. it contains the package folders like:

src
 -org
   -module
     -MyClass1.java
     -MyClass2.java
2
  • Thanks. It was an issue with the dir I was specifying in the fileset. Changing the "fw" to "." resolved my issue.
    – Jeff
    Jun 8, 2012 at 12:19
  • Thanks, this answer helped me. Initially I had dir="src" and had the same issue as the author, however when changed it to dir="src/main/java" I got my source coverage.
    – Kirill G.
    Oct 10, 2016 at 11:23
1

I’ve seen this break when using Scala-style package directory names, e.g.,

src/main/java/com.example.foo.bar/Foo.java

for fewer levels of nesting, faster autocompletion, &c., compared to the standard

src/main/java/com/example/foo/bar/Foo.java

Most tools support the first version just fine, but usually if you try it out and everything works fine, by the time you notice something like the jacoco reports not showing the source anymore, you’ve long forgotten the directory name change …

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.