Define excludes for multi module maven projects

4,395 views
Skip to first unread message

delcorny

unread,
Dec 16, 2020, 9:58:50 AM12/16/20
to JaCoCo and EclEmma Users
Hello,

I have an multi module maven project and and want to define excludes in the parent pom. I did some entries but there is no effect. When I check the site/jacoco/index.hmtl I still see measurements in the module I have excludes (i.e. abc ). For other modules I also found that coding in  **/test/abc.java has been scanned. 

<profile>
<!-- Code Coverage - Jacoco -->
<id>codecoverage</id>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.4</version>
<configuration>
<excludes>
<exclude>**/src/main/java/abc/*.java</exclude>
<exclude>**/test/**</exclude>
</excludes>
</configuration>
<executions>
<execution>
<id>pre-unit-test</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>

Evgeny Mandrikov

unread,
Dec 16, 2020, 10:05:53 AM12/16/20
to JaCoCo and EclEmma Users
Please read documentation https://www.jacoco.org/jacoco/trunk/doc/report-mojo.html#excludes
which states that excludes property of report goal refers to class files and not to source files:
A list of class files to exclude from the report

Instead
<exclude>**/src/main/java/abc/*.java</exclude>
you probably need
<exclude>abc/*.class</exclude>

Patrick Cornelius

unread,
Dec 16, 2020, 3:21:51 PM12/16/20
to jac...@googlegroups.com
Hello,

the issue is that also all files below the path '**/test/**' is also checked. So the exclude has not been taken.

So is the wildcard in the beginning needed like **/test/**/*.class or test/**/*.class. 

BR,
Patrick

--
You received this message because you are subscribed to a topic in the Google Groups "JaCoCo and EclEmma Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jacoco/b1vAV3Q7wis/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jacoco+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jacoco/b230223a-d006-424f-a497-7fd15a330752n%40googlegroups.com.

Evgeny Mandrikov

unread,
Dec 16, 2020, 3:33:48 PM12/16/20
to JaCoCo and EclEmma Users
On Wednesday, December 16, 2020 at 9:21:51 PM UTC+1 delcorny wrote:
Hello,

the issue is that also all files below the path '**/test/**' is also checked. So the exclude has not been taken.

So is the wildcard in the beginning needed like **/test/**/*.class or test/**/*.class. 
 
Both are valid patterns for class files
second one will match
target/classes/A/test/B/C.class
and
target/classes/test/D/E.class
while second one will match only later.

I don't know which one is suitable in your case without access to your project.
Either provide it or try both by yourself.

Patrick Cornelius

unread,
Dec 18, 2020, 4:57:12 AM12/18/20
to jac...@googlegroups.com
I gave them a new try 

<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${version.jacoco}</version>
<configuration>
<excludes>
<exclude>jmeter/**/*.class</exclude>
<exclude>**/jmeter/**/*.class</exclude>
<exclude>codes/**/*.class</exclude>
<exclude>**/*Code*.class</exclude>

</excludes>
</configuration>
<executions>
<execution>
<id>pre-unit-test</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>

The result is that the following files are taken and I has expected that they are not considered (this is the outcome from sonar) when pushing the results but also all these modules have jacoco/index.html and the files are considered there.


  



Evgeny Mandrikov

unread,
Dec 18, 2020, 5:24:41 AM12/18/20
to JaCoCo and EclEmma Users
In example.zip attachment you'll find complete example which shows that excludes specified in parent pom are inherited in child modules and correctly applied - there is no A1 and B1 classes in the html report:

example.png
So once again:
unlikely that based on partial code snippets somebody will be able to blindly guess what is going wrong in your case
either provide all your code
or carefully debug, double-check it and compare with this example by yourself, e.g. by executing Maven in debug (option "-X") and making sure that configuration defined in parent and present for children

example.zip

Patrick Cornelius

unread,
Dec 18, 2020, 6:44:39 AM12/18/20
to jac...@googlegroups.com
Thanks for the support and the simple example .. I tried that but my main point is that modules are not prevented from scanning. Also in your example no possibility

<exclude>**/a/*.class</exclude>
<exclude>a/*.class</exclude>
<exclude>**/a/**</exclude>

Evgeny Mandrikov

unread,
Dec 18, 2020, 7:14:38 AM12/18/20
to JaCoCo and EclEmma Users
 
I tried that but my main point is that modules are not prevented from scanning.

No idea what do you mean by "scanning".
If this is about SonarQube, then integration with it is not developed by us, so please refer to its documentation and support channels - see for example https://docs.sonarqube.org/latest/project-administration/narrowing-the-focus/

Also in your example no possibility

<exclude>**/a/*.class</exclude>
<exclude>a/*.class</exclude>
<exclude>**/a/**</exclude>

Yes - you can not use module name within pattern, because patterns are relative to the module.

You can place module-specific exclusions into module itself.

Also different modules usually have different packages (see also Java 9 modularity and "split packages"),
so that you can use package name in patterns.

And for more flexibility in configuring things you can also resort to usage of JaCoCo Ant tasks via maven-ant-plugin.

Reply all
Reply to author
Forward
0 new messages