How to exclude unrelated packages from being generate in site->jacoco

14,094 views
Skip to first unread message

vered.co...@gmail.com

unread,
May 29, 2018, 4:33:03 AM5/29/18
to JaCoCo and EclEmma Users
Hello,

I understand I can exclude packages and classes with this configuration for example:
<configuration>
<excludes>
<exclude>**/*JavaProjectApi.class</exclude>
<exclude>com.sun.*</exclude>
</excludes>
</configuration>

However I encountered 2 issues while defining jacoco in multi maven module. I have one module that shows a very low coverage (0.002) although when I run jacoco in eclipse I get an higher result (50%+).
When I build this module I get in the target folder jacoco.exec generated and in the site/jacoco folder I see a lot of packages that are unrelated directly to this module. For example I see 50 folders of org.apache.olingo etc. which probably is the cause for reducing the overall coverage.

1) What causes them to be added in the first place?

I tries to exclude this package
<configuration>
<excludes>
<exclude>org.apache.olingo.*</exclude>
</excludes>
</configuration>
from several places but I still see these packages in the jacoco->site.

2) How exactly can ignore them so that they will not be added at all to the index.html report in jacoco/site and will not effect the coverage percentage?

I would be grateful for your help!
Thanks a lot in advance!
Vered

Marc Hoffmann

unread,
May 29, 2018, 7:15:19 AM5/29/18
to jac...@googlegroups.com
Hi Vered,

1) The report goal by default processes all class files under the
target/classes folder. Maybe your build copies additional classes there?
2) For the report goal excludes/includes denotes class *files*. So the
pattern would be <exclude>org/apache/olingo/*</exclude>

Regards,
-marc

vered.co...@gmail.com

unread,
May 29, 2018, 5:32:50 PM5/29/18
to JaCoCo and EclEmma Users
Hello Marc,

Thank you so much for your advice!
You were right! In the build process it copies additional classes so that it allows a local maven repository..
For one module I could remove this build part and succeed to see the report I wanted, but for the other module its essential to copy these classes..
Even if I added the following in the pom:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<executions>
<execution>
<id>jacoco-report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<excludes>
<exclude>org/apache/olingo/*</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>

I saw org/apache/olingo folders generated in jacoco->site and in the report.

This is how this build section of this pom looks like..

<build>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
<resource>
<directory>${project.build.directory}/unpackdependencies</directory>
<filtering>false</filtering>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>process-sources</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.some.group.id</groupId>
<artifactId>java-maven-repo-builder</artifactId>
<version>${project.version}</version>
<classifier>bin</classifier>
<type>zip</type>
<overWrite>false</overWrite>
<outputDirectory>${project.build.directory}/unpackdependencies</outputDirectory>
<destFileName>java-maven-repository.zip</destFileName>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<executions>
<execution>
<id>jacoco-report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<excludes>
<exclude>org/apache/olingo/*</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

Since it is part of the build nothing that I do to exclude these packages worked.
Do you have any suggestion in this case?
Thanks in advance!
Vered

Evgeny Mandrikov

unread,
May 29, 2018, 6:35:16 PM5/29/18
to JaCoCo and EclEmma Users
Hi Vered,

Since you are mentioning "site", I'm wondering if you are executing jacoco report separately or as a part of execution of maven-site-plugin ?

"
Configuring a reporting plugin in the <reporting> or <build> elements in the pom does NOT have the same behavior!
mvn site
It uses only the parameters defined in the <configuration> element of each reporting Plugin specified in the <reporting> element, i.e. site always ignores the parameters defined in the <configuration> element of each plugin specified in <build>.
"

In former case let me highlight that property excludes of report goal specifies file locations (not class names) under target/classes directory should be excluded from analysis during generation of report . E.g. if you have "target/classes/lib/org/apache/olingo/", then exclusion must include "lib" part. https://stackoverflow.com/a/50294239/244993 contains example demonstrating this. As a side note: semantic of property excludes of prepare-agent goal is different ( https://github.com/jacoco/jacoco/issues/34#issuecomment-10205525 ) - it specifies class names (regardless of their on-disk location) that should be excluded from instrumentation during execution of tests.

P.S. as you can see just a snippet of POM is clearly not enough to fully understand your problem, to avoid wild guessing please consider providing complete (yet minimal) example that demonstrates your problem.

Hope this helps.

vered.co...@gmail.com

unread,
May 30, 2018, 5:03:42 AM5/30/18
to JaCoCo and EclEmma Users
Hello Evgeny,

I'm so grateful for your answer!!
I am the first to integrate Jacoco in our group repositories so I had no one to consult with. So your help is blessed!

I apologize for giving only snippet of the pom, I didn't want to give overload of information but of course you are right and this was necessary :)

Finally I excluded the zip file itself that was generated during build and it worked!

I don't use maven-site-plugin..I mention site just because it is the folder where I can see the generated report index.html and so to make sure the coverage is what I expected it to be (percentages, classes included/excluded...)

I suppose the index.html reports reflect the jacoco.exec files. The execs will be consumed by our SonarQube by configuring the paths to all the jacoco files. As of my understanding in this way they can be merge so that the final result will be a merged report.

Thank you again for all your help!
Best Regards,
Vered

Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages