Format for includes parameter for jacocoagent

125 views
Skip to first unread message

Kishore Mohanavelu

unread,
Dec 30, 2020, 3:26:26 AM12/30/20
to JaCoCo and EclEmma Users
Hi Guys,

I would like to specify only a list of classes under a particular package(eg: com.server) to be analysed by jacoco. I don't want other classes under different package to be considered for code coverage. I am specifying the package as below, but it is not working.

Option 1 - Tried:
-javaagent:jacocoagent.jar=address=localhost,port=8084,includes=**/com/server/**,destfile=jacoco_output.exec,output=tcpserver -cp . -jar ironhide.jar server config.yml &

Option- 2 - Tried:
-javaagent:jacocoagent.jar=address=localhost,port=8084,includes=**.com.server.**,destfile=jacoco_output.exec,output=tcpserver -cp . -jar ironhide.jar server config.yml &

What is the format that I have to specify in the includes parameter? Can someone help please? 

Evgeny Mandrikov

unread,
Dec 30, 2020, 3:32:10 AM12/30/20
to JaCoCo and EclEmma Users
Quoting https://www.jacoco.org/jacoco/trunk/doc/faq.html

Why do I see classes in the coverage report although I excluded them in the JaCoCo agent configuration?

The includes and excludes options of the JaCoCo agent determine for which classes execution data is collected. Except for technical corner cases these options are normally not required. If you exclude classes, no execution data is collected for them.

Report creation is a separate step where all class files which should show up in the report are explicitly provided. Coverage is determined from the provided execution data. If execution data is missing for a particular class, this class is shown as not covered because the report generator cannot distinguish whether the class was excluded from instrumentation or not executed.

If you want to exclude classes from the report please configure the respective report generation tool accordingly.


Kishore Mohanavelu

unread,
Dec 30, 2020, 3:48:10 AM12/30/20
to JaCoCo and EclEmma Users
Hi Evgeny,

Thanks for your reply. I am attaching the jacoco agent to the jvm of each service, by doing ssh into the service and executing commands in terminal. And I have to create a jacocoreport by using the jar of that particular service(This is to get the compiled list of classes from the jar). But currently, jacoco is analysing all the maven dependencies of the services as well. So I would like to provide a package restriction. May I know how to achieve this please

Thanks,
Kishore Mohanavelu

Evgeny Mandrikov

unread,
Dec 30, 2020, 3:57:04 AM12/30/20
to JaCoCo and EclEmma Users
On Wednesday, December 30, 2020 at 9:48:10 AM UTC+1 Kishore Mohanavelu wrote:
Hi Evgeny,

Thanks for your reply. I am attaching the jacoco agent to the jvm of each service, by doing ssh into the service and executing commands in terminal. And I have to create a jacocoreport by using the jar of that particular service(This is to get the compiled list of classes from the jar). But currently, jacoco is analysing all the maven dependencies of the services as well. So I would like to provide a package restriction. May I know how to achieve this please

If you create report using JaCoCo Command Line interface, then use "--classfiles" parameter to specify only classes that you want - see https://www.jacoco.org/jacoco/trunk/doc/cli.html
For example by unzipping your JAR into temporary directory and removing unwanted classes.
Please have a look at the documentation and already existing answers, for example similar scenario was already discussed in https://groups.google.com/g/jacoco/c/0QkOV5u1w6Y/m/Aept20V_AgAJ

Kishore Mohanavelu

unread,
Dec 30, 2020, 4:02:35 AM12/30/20
to JaCoCo and EclEmma Users
Thank you Evgeny. The idea you proposed definitely helps! Will try it out and update here!
Reply all
Reply to author
Forward
0 new messages