Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

java - JaCoCo Not Generating Coverage Reports based on Source File - Method names not clickable

I have a Maven multi module project where the JaCoCo is not generating reports based on the source files.

Generally, if MyService is the class under test, it would be reported in two ways, one through a file name MyService.html in appropriate package based location with a list of methods giving an overall picture of the coverage in numbers and graphs - with listing of all the methods in the class and each method has a clickable link to another html MyService.java.html which contains the source code with red/green/yellow background to display coverage status.

In my scenario, only MyService.html is generated and not the MyService.java.html and methods are listed in the former with coverage details, but without hyperlinks to the other report as displayed below.

enter image description here

Issue gets more interesting here that my Maven configuration is not configured in this module, but in a parent module and other child modules are able to generate reports properly. Below is the maven plugin configuration for reference.

Parent POM:

<plugin>
  <groupId>org.jacoco</groupId>
  <artifactId>jacoco-maven-plugin</artifactId>
  <version>${jacoco.version}</version>
  <configuration>
     <destFile>${project.basedir}/target/jacoco-unit.exec</destFile>
     <dataFile>${project.basedir}/target/jacoco-unit.exec</dataFile>
     <append>true</append>
  </configuration>
  <executions>
     <execution>
        <id>jacoco-initialize</id>
        <goals>
           <goal>prepare-agent</goal>
        </goals>
     </execution>
     <execution>
        <id>jacoco-site</id>
        <phase>package</phase>
        <goals>
           <goal>report</goal>
        </goals>
     </execution>
  </executions>
</plugin>

Child POM:

    <plugin>
        <groupId>org.jacoco</groupId>
        <artifactId>jacoco-maven-plugin</artifactId>
    </plugin>

Tried switching JaCoCo versions, but none helped, now sticking to the latest 0.8.2. And Maven is latest - 3.6.0. Apart from this, the other plugin configured in the child pom is PMD - whose presence or absence did not make any difference to report.

Similar issue: Gradle JaCoCo plugin - class and method names not clickable in report

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

In absence of Minimal, Complete, and Verifiable example that fully demonstrates steps to reproduce your difficulty, can only quote JaCoCo FAQ :

Why does the coverage report not show highlighted source code?

Make sure the following prerequisites are fulfilled to get source code highlighting in JaCoCo coverage reports:

  • Class files must be compiled with debug information to contain line numbers.
  • Source files must be properly supplied at report generation time.

About first point see -g option of javac, debug and debuglevel options of maven-compiler-plugin.

For the second point make sure that source file Example.java with

package org.example;

is located in src/main/java/org/example/Example.java


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...