Same result when exclusion in plugin configuration and in report generation command line

767 views
Skip to first unread message

Mehul Parmar

unread,
Jun 27, 2023, 1:19:36 PM6/27/23
to JaCoCo and EclEmma Users
Hello, 
I want to know do we get same code coverage reports in these 2 cases - 
1. Using jacoco-maven-plugin and excluding classes from config and then generating report - 
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.10</version>
<configuration>
<excludes>
<exclude>com/abc/xyz/samples/impl/**/*</exclude>
</excludes>
</configuration>


2. Generating a Jacoco exec without any exclusion and then applying exclusion from the command line. 

java -jar /path/to/jacoco-cli.jar report jacoco.exec --classfiles /path/to/classes --html /path/to/report --excludes='*'

Also when I run the second command,  I noticed the exclusion is not applying and I am getting the complete report as it is in jacoco.exec. Then what is the point of giving exclusion in report command?

Thanks

Mehul Parmar

unread,
Jun 28, 2023, 2:24:27 AM6/28/23
to JaCoCo and EclEmma Users
Hello,
My exact command is this for generating report with exclusions on vanilla Jacoco

java -jar /Users/mehul/Downloads/org.jacoco.cli-0.8.10-nodeps.jar report /Users/mehul/Documents/jacoco_results/new_uts/default_plugin_no_custom/jacoco.exec --classfiles /Users/mehul/Repos/mehparmar/abc/abcService/target/classes --excludes='com/abc/pqr/samples/impl/*' --html ./report

Evgeny Mandrikov

unread,
Jun 28, 2023, 5:03:07 AM6/28/23
to JaCoCo and EclEmma Users
 
On Tuesday, June 27, 2023 at 10:49:36 PM UTC+5:30 Mehul Parmar wrote:
2. Generating a Jacoco exec without any exclusion and then applying exclusion from the command line. 

java -jar /path/to/jacoco-cli.jar report jacoco.exec --classfiles /path/to/classes --html /path/to/report --excludes='*'

Also when I run the second command,  I noticed the exclusion is not applying and I am getting the complete report as it is in jacoco.exec. Then what is the point of giving exclusion in report command?

As you can see in the documentation at https://www.jacoco.org/jacoco/trunk/doc/cli.html
and as well by executing

java -jar /path/to/jacoco-cli.jar report

The command line interface has no such parameter as "--excludes".

To exclude something using the command line interface remove it from the location specified by "--classfiles".

Evgeny Mandrikov

unread,
Jun 28, 2023, 5:27:52 AM6/28/23
to JaCoCo and EclEmma Users
Also I created following ticket https://github.com/jacoco/jacoco/issues/1490

Mehul Parmar

unread,
Jun 28, 2023, 6:06:36 AM6/28/23
to JaCoCo and EclEmma Users
Hello,
Thank you for confirming this. Also help with my frst doubt. Doing these two things create same coverage result ?


1. Using jacoco-maven-plugin and excluding classes from config and then generating report - 
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.10</version>
<configuration>
<excludes>
<exclude>com/abc/xyz/samples/impl/**/*</exclude>
</excludes>
</configuration>


2. Generating a Jacoco exec without any exclusion and then not including classFiles(com/abc/xyz/samples/impl/**/*) while generating report. 

Mehul Parmar

unread,
Jun 28, 2023, 12:59:40 PM6/28/23
to JaCoCo and EclEmma Users
Hello,
For me these 2 above steps are generating the same results. Is it proper thing to do to get exec file without any exclusions and then applying everything at the report stage?

Marc Hoffmann

unread,
Jun 29, 2023, 4:21:57 AM6/29/23
to JaCoCo and EclEmma Users
Hi Mehul,

yes, this the correct approach: To set the scope of the report you filter the classes at report stage.

If you would filter at execution stage you would simply not collect data for those classes but the classes will still show up in the report (as uncovered).

Regards,
-marc

-- 
You received this message because you are subscribed to the Google Groups "JaCoCo and EclEmma Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jacoco+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jacoco/6d2ff7a7-9aa8-47bb-99fe-a162f993532en%40googlegroups.com.

Mehul Parmar

unread,
Jun 29, 2023, 9:06:06 AM6/29/23
to JaCoCo and EclEmma Users
Hello Marc,
Thank you for confirming that both the appraoches will give same result. But in my analysis it was a little bit different.
Step 1) I added some exclusions in jacoco-maven-plugin and ran the tests. I got an exec and report from the plugin which did not have those excluded classes at all in the report.
Step 2) When I used report command and selected all classes from target folder of project and jacoco.exec from previous step(generated by plugin), then somehow I got coverage of excluded classes as well in HTML report. How is that possible? The Jacoco.exec should not have coverage data of excluded classes.

1) Step 1
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.10</version>
<configuration>
<excludes>
<exclude>com/abc/xyz/samples/init/**/*</exclude>
<exclude>com/abc/pqr/samples/impl/**/*</exclude>
</excludes>
</configuration>
<executions>

Step 2)
java -jar /Users/mehul/Downloads/org.jacoco.cli-0.8.10-nodeps.jar report /Users/mehul/Repos/mehul/abc/abcService/target/jacoco.exec --classfiles /Users/mehul/Repos/mehul/abc/abcService/target/classes --html ./report

Marc Hoffmann

unread,
Jun 29, 2023, 11:12:24 AM6/29/23
to jac...@googlegroups.com
Hi Mahul,

as I tried to explain: All *.class files you supply to the report command will show up in the report. The conten of the *.exec file does not define the scope of the report.

Regards,
-marc

On 29. Jun 2023, at 16:06, 'Mehul Parmar' via JaCoCo and EclEmma Users <jac...@googlegroups.com> wrote:

Hello Marc,

Evgeny Mandrikov

unread,
Jun 29, 2023, 11:15:27 AM6/29/23
to jac...@googlegroups.com
And earlier I tried to explain the same thing as Marc:

To exclude something using the command line interface remove it from the location specified by "--classfiles".
--
Regards,
Evgeny

Mehul Parmar

unread,
Jun 30, 2023, 1:51:30 AM6/30/23
to JaCoCo and EclEmma Users
Hello Marc,
Perhaps I was not clear. Yes in Step 2 report command I am passing all the class files, but in HTML report for excluded classes(in plugin) coverage should come as uncovered. Why? Because Jacoco.exec is generated from the plugin(Step 1) config which has the exclusions, so exec file should not have coverage data. So indeed classes will come in report as I am passing them in "--classfiles" but coverage should be uncovered. 

So it seems like Jacoco.exec(/Users/mehul/Repos/mehul/abc/abcService/target/jacoco.exec) generated from plugin with exclusions, has data of all classes which are excluded in configuration.  And when I check the report generated by plugin in Step 1, it does not have excluded classes at all in report which is expected. 



<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.10</version>
<configuration>
<excludes>
<exclude>com/abc/ra/samples/init/**/*</exclude>
<exclude>com/abc/ra/samples/impl/**/*</exclude>
</excludes>
</configuration>
<executions>
<!--first execution : for preparing JaCoCo runtime agent-->
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<!--second execution : for creating code coverage reports-->
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>

Marc Hoffmann

unread,
Jun 30, 2023, 5:05:22 AM6/30/23
to JaCoCo and EclEmma Users
Hi Mehul,

when you click in the “Sessions” link in the top right of the coverage report you see a list of all classes in the the exec file

Also note that the “excudes” option for the prepare agent has a slightly different format than the report “excludes” (class names vs. file names). Please see documentation:



Cheery,
-marc

Mehul Parmar

unread,
Jun 30, 2023, 12:50:55 PM6/30/23
to JaCoCo and EclEmma Users
Hey Marc,
Yes that worked. Thank you. I had to give explicit class name in configuration. But how it will work when I have to exclude a package by using wildcard characters (* and ?). If I just give <exclude>com/abc/ra/samples/init/**/*</exclude> then how to explicit mention that exclude class(prepare-agent) and not java files(report). 

<configuration>
<excludes>
<exclude>com/abc/ra/samples/impl/ClassA</exclude>
<exclude>com/abc/ra/samples/init/ClassB</exclude>
</excludes>
</configuration>

Mehul Parmar

unread,
Jul 1, 2023, 11:19:42 AM7/1/23
to JaCoCo and EclEmma Users
Hello,
Can you help me in excluding a package from prepare-agent phase? When I provide exclusion by using wildcard characters (* and ?) like <exclude>com/abc/ra/samples/init/**/*</exclude> then it excludes from report but not from exec file. 

Marc Hoffmann

unread,
Jul 2, 2023, 2:39:34 AM7/2/23
to jac...@googlegroups.com
Hi,

JaCoCo agent supports wild cards (* and ?). It does not support glob patterns (/**/). See documentation: https://www.jacoco.org/jacoco/trunk/doc/agent.html

Also I wonder why you want to exclude these clesses from the agent, As documentation says: "Except for performance optimization or technical corner cases this option is normally not required."

Regards,
-marc



Evgeny Mandrikov

unread,
Jul 2, 2023, 3:47:32 AM7/2/23
to jac...@googlegroups.com
how to explicit mention that exclude class(prepare-agent) and not java files(report). 

Please refer to the Maven documentation about how to configure plugins - you can specify excludes in the configuration of the single goal prepare-agent, not for the entire plugin, ie

<configuration>
  <!-- applies to all executions of all goals -->
</configuration>
<executions>
  <execution>
    <goals><goal>prepare-agent</goal></goals>
    <configuration>
      <!-- applies only for this execution of this goal -->
    </configuration>
--
Regards,
Evgeny

Mehul Parmar

unread,
Jul 2, 2023, 5:41:06 AM7/2/23
to JaCoCo and EclEmma Users
Hello, 
Yes, I will get same coverage if I get an exec with all classes and then filter in report or if I filter in exec itself(agent stage) and then filter in report. But for big Java projects wanted to skip calculating coverage and record in exec, so yes a little bit of performance optimizations. 
And yes, excluding package in prepare-agent goal worked! 

Mehul Parmar

unread,
Jul 4, 2023, 2:07:09 AM7/4/23
to JaCoCo and EclEmma Users
Hello,
Can you confirm this? Jacoco java agent accepts '.' naming convention
-javaagent:[yourpath/]jacocoagent.jar=excludes=com.abc.package.*
-javaagent:[yourpath/]jacocoagent.jar=excludes=com.abc.package.ClassA

But java-maven-plugin and jacococli accepts '/' convention 

<configuration>
<excludes>
<exclude>com/abc/ra/sample/init/*</exclude>
</excludes>
</configuration>

java -jar /Users/mehul/Downloads/org.jacoco.cli-0.8.10-nodeps.jar report /Users/mehul/Repos/mehul/abc/abcService/target/jacoco.exec --classfiles /Users/mehul/Repos/mehul/abc/abcService/target/classes --html ./report

Evgeny Mandrikov

unread,
Jul 4, 2023, 11:24:48 AM7/4/23
to jac...@googlegroups.com
See 

--
You received this message because you are subscribed to the Google Groups "JaCoCo and EclEmma Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jacoco+un...@googlegroups.com.
--
Regards,
Evgeny

Evgeny Mandrikov

unread,
Jul 4, 2023, 11:31:39 AM7/4/23
to jac...@googlegroups.com


On Tue, 4 Jul 2023 at 17:24, Evgeny Mandrikov <mand...@gmail.com> wrote:
See 

ie both slash (/) and dot (.) separated notations (VM and Java names) are accepted by agent

while report Maven goal expects filenames
--
Regards,
Evgeny

Mehul Parmar

unread,
Jul 6, 2023, 2:48:33 AM7/6/23
to JaCoCo and EclEmma Users
Hello,
We have 2 questions. Can you help on these - 

1) How to pass classes to Jacoco Agent when project is multi module? Excludes in Jacoco Agent only takes a list of classes. Then there are chance of collision if package name and Class name is same. How Jacoco agent will handle that? Also, do you have an example of passing classes from a multi module project?

2) How to pass jar to jacoco Agent to exclude/include or is it not allowed and we need to extract jar to get all classes and then supply to jacoco java agent.

Thank you for answering previous questions. It helps a lot. 

Regards
Mehul

Message has been deleted

Mehul Parmar

unread,
Jul 7, 2023, 8:10:24 AM7/7/23
to JaCoCo and EclEmma Users
Hello,
We have 3 questions. Our use case is we have several modules in a java project. Only one main service module is converted to classes and rest modules are converted to jar. For the module converted to classes its straight forward to get coverage but not for libs.
These questions are related to that - 

1) How to pass classes to Jacoco Agent when project is multi module? Excludes in Jacoco Agent only takes a list of classes. Then there are chance of collision if package name and Class name is same. How Jacoco agent will handle that? Also, do you have an example of passing classes from a multi module project?

2) Can we pass jar name also with inclusion/exclusions classes(like a map jar:[classes]) to jacoco Agent to exclude/include? This is to specify from this jar file exclude/include these classes.
The issue is we dont know which jar's classes are passed in JavaAgent. Our application can only list read list of classes from java Agent Config, no information about these classes belong to which jar originally.

3) When we are merging multiple Jaoco exec and each one has its own inclusion and exclusions. Then what would make more sense in generating reports? 
     a) union of inclusions and intersection of exclusions
     b) union of inclusions and union of exclusions


Regards
Mehul

Marc Hoffmann

unread,
Jul 7, 2023, 9:56:57 AM7/7/23
to JaCoCo and EclEmma Users
Hi Mehul,

I still don’t understand why you want to configure the exclusions for the agent. Have you measured any differences in execution performance? I think this adds needless complexity to your build. Regarding your questions:

1) If you really want you can provide a JaCoCo configuration separately for every Maven modul
2) No, only class names
3) Just merge them

Regards,
-marc


Mehul Parmar

unread,
Jul 7, 2023, 1:42:25 PM7/7/23
to JaCoCo and EclEmma Users
Hello Marc, 
We are running Jacoco in server mode in a GCP vm i.e. server mode. So our application(container) is running inside that vm along with Jacoco agent(second container). Our another application sends a dump request to that vm and get the Jacoco.exec and generates the report.

Regarding your answer

1) How will I send Jacoco config for each module to a single Jacoco Agent in a single request? Can you explain with an example? 
2) Jacoco.exec would be merged that is not an issue. Issue is how to interpret exclusions and inclusions. We actually do multiple Test runs of a single application and merge them.

In one TestRun I included let say class A,B,C and excluded C
in second TestRun I class A, P, Q and excluded Q.

Now when I merge them, in inclusion I will consider union of classes means A,B,C,P,Q but in exclusion what should make more sense?
a) Union of exclusion - C,Q
b) intersection of exclusions - NIL, so all classes are included in report.


Regards
mehul
Reply all
Reply to author
Forward
0 new messages