How to create Jacoco code coverage from jacoco.exec file that is generated from JAR file?

一曲冷凌霜 提交于 2021-01-29 08:31:17

问题


I have been looking to generate code coverage from jar build file,with jacoco.

I found this command

java -jar jacococli.jar dump [--address <address>] --destfile <path> [--help] [--port <port>] [--quiet] [--reset] [--retry <count>]

to make it work but have no idea how to generate jacococli.jar . I normally added as dependecy but nothing happened.

<dependencies>
  <dependency>
    <groupId>org.jacoco</groupId>
    <artifactId>org.jacoco.cli</artifactId>
    <version>0.8.3</version>
</dependency>
</dependencies>

回答1:


I found this command

java -jar jacococli.jar dump [--address <address>] --destfile <path> [--help] [--port <port>] [--quiet] [--reset] [--retry <count>]

... added as dependecy but nothing happened

jacococli.jar is not intended to be used as a dependency - command is shown in JaCoCo documentation on page https://www.jacoco.org/jacoco/trunk/doc/cli.html which states

JaCoCo comes with a command line interface to perform basic operations from the command line.

and later also states

For more sophisticated usage especially with larger projects please use our integrations with various build tools.

among integrations there is jacoco-maven-plugin for generation of report using Maven, documentation of this plugin available on page https://www.jacoco.org/jacoco/trunk/doc/maven.html


To use jacococli.jar for generation of report from jacoco.exec file for your.jar file

  1. download zip distribution of JaCoCo from https://www.jacoco.org/jacoco/
  2. extract it for example into directory jacoco, jacococli.jar will be in jacoco/lib/jacococli.jar
  3. open command line in this directory and execute
java -jar lib/jacococli.jar report path/to/jacoco.exec --classfiles path/to/your.jar --html path/for/report
  1. HTML report will be in directory path/for/report


来源:https://stackoverflow.com/questions/55397944/how-to-create-jacoco-code-coverage-from-jacoco-exec-file-that-is-generated-from

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!