Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent includes/excludes options for Maven report goal #34

Open
marchof opened this issue Oct 15, 2012 · 15 comments
Open

Inconsistent includes/excludes options for Maven report goal #34

marchof opened this issue Oct 15, 2012 · 15 comments
Labels
component: maven type: bug 🐛 Something isn't working

Comments

@marchof
Copy link
Member

marchof commented Oct 15, 2012

For the JaCoCo agent, Ant Tasks and Maven goals the format of the class names to include/exclude needs to be properly specified.

Also the change log for 0.5.4 probably shows the wrong format.

@marchof
Copy link
Member Author

marchof commented Nov 8, 2012

These are the different notations for classes we have:

  • VM Name: java/util/Map$Entry
  • Java Name: java.util.Map$Entry
  • File Name: java/util/Map$Entry.class

Agent Parameters, Ant tasks and Maven prepare-agent goal

  • includes: Java Name (VM Name also works)
  • excludes: Java Name (VM Name also works)
  • exclclassloader: Java Name

These specifications allow wildcards * and ?, where * wildcards any number of characters, even multiple nested folders.

Maven report goal

includes: File Name
excludes: File Name

These specs allow Ant Filespec like wildcards *, ** and ?, where * wildcards parts of a single path element only.

@wuwen5
Copy link

wuwen5 commented Dec 20, 2016

+1

1 similar comment
@Diego-Rocha
Copy link

+1

@spaceCamel
Copy link

spaceCamel commented Apr 19, 2017

+1
I'm trying to exclude all the content of the com.mycompany.ignore_this package but so far no luck. This is what I put in my root pom.

<plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <executions>
        <execution>
            <id>default-prepare-agent</id>
            <goals>
                <goal>prepare-agent</goal>
            </goals>
        </execution>
        <execution>
            <id>default-report</id>
            <phase>prepare-package</phase>
            <goals>
                <goal>report</goal>
            </goals>
        </execution>
        <execution>
            <id>default-check</id>
            <goals>
                <goal>check</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <excludes>
            <exclude>com.mycompany.ignore_this.*</exclude>
        </excludes>
    </configuration>
</plugin>

I also tried to exclude it in the prepare-agent and report executions, but didn't work: the packages keep on showing on the reports.
Jacoco docs did not help much in my case. Have I missed something?

@marchof
Copy link
Member Author

marchof commented Apr 19, 2017

@spaceCamel The report goal is the correct place to exclude classes or packages from the report (I assume this is what you want to achieve). As stated in my issue above for the report goal the excludes list refers to file names. So in your case the configuration would be:

<exclude>com/mycompany/ignore_this/*</exclude>

@spaceCamel
Copy link

@marchof thanks for pointing that out again. Indeed if I put <exclude>com/mycompany/ignore_this/*</exclude> in the report configuration I get all the classes under the package com.mycompany.ignore_this excluded. I was misled by the fact that SonarQube code-quality service is still displaying these classes.
I noticed it picks up the jacoco.exec files during analysis. Do you know what those files contains?

@marcrohlfs
Copy link

+1
I'd suggest to use different property names for different semantics. Currently it's not possible to unify includes and excludes (e.g. in pluginManagement), because it can only work for whether agent preparation or report creation.

@barclay-reg
Copy link

@Godin do you have any idea, how to fix this?

@addu390
Copy link

addu390 commented Jul 14, 2019

Did anyone find a solution for this ?
Even though exclude works fine, the report still shows all files

@zhudaxi
Copy link

zhudaxi commented Jun 8, 2020

@spaceCamel The report goal is the correct place to exclude classes or packages from the report (I assume this is what you want to achieve). As stated in my issue above for the report goal the excludes list refers to file names. So in your case the configuration would be:

<exclude>com/mycompany/ignore_this/*</exclude>

When i tried the parameter in "report" goal, it dose not work. When I change the parameter in "prepare-agent" goal, it works. Not sure why this happens.

@obol007
Copy link

obol007 commented Nov 5, 2020

@marchof Hi, is there any solution to excluding packages/classes in a JaCoCo report yet?
Non of these is working:
<execution> <id>report</id> <phase>prepare-package</phase> <goals> <goal>report</goal> </goals> <configuration> <excludes> <exclude>**/controllers/SingleTopologyController.java </exclude> <exclude>**/controllers.SingleTopologyController </exclude> <exclude>**/controllers/* </exclude> </excludes> </configuration> </execution>

@marchof
Copy link
Member Author

marchof commented Nov 5, 2020

@obol007 If you specify patterns for CLASS FILES this should work, like your last exclude:

<exclude>**/controllers/* </exclude>

I assume it does not work due to the whitespace at the end.

@obol007
Copy link

obol007 commented Nov 5, 2020

@obol007 If you specify patterns for CLASS FILES this should work, like your last exclude:

<exclude>**/controllers/* </exclude>

I assume it does not work due to the whitespace at the end.

@marchof I moved <configuration> to the top and now it's working like a champ! Thanks for the asnwer!
<groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <version>0.8.6</version> <configuration> <excludes> <exclude>**/controllers/*</exclude> </excludes> </configuration> <executions>

@theKashyap
Copy link

theKashyap commented Dec 1, 2022

Only thing that worked for me is to

  • put exclude config directly under the <plugin> tag and
  • use regex/filters to match "File name" (a/b/C.class), not "Java name" or "VM name" (See definitions of names here.

Took the sample from here.

This will apply to all executions, i.e. it'll be excluded from report and check. Here is the smallest pom.xml that worked for me, removed tags whose values were default.

<plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <configuration>
        <excludes>
            <exclude>com/mycompany/ignore_this/*</exclude>
            <!-- wildcard "**" also works -->
            <!-- <exclude>**/ignore_this/*</exclude> -->
        </excludes>
    </configuration>
    <executions>
        <execution>
            <id>default-report</id>
            <goals>
                <goal>report</goal>
            </goals>
        </execution>
        <execution>
            <id>default-check</id>
            <goals>
                <goal>check</goal>
            </goals>
        </execution>
    </executions>
</plugin>

Works with 0.8.8

@BlackViper3
Copy link

BlackViper3 commented Nov 6, 2023

The solution that worked for me is to do the following

  • Define the groupId
    <groupId>com.domainname.package</groupId>

  • Define Maven property using the groupId property

<properties>
        <code-coverage.line-covered-ratio.min>0.75</code-coverage.line-covered-ratio.min>
        <code-coverage.package.exclude-applicationclass>${project.groupId}</code-coverage.package.exclude-applicationclass>
        <code-coverage.package.exclude-beanclass>${project.groupId}/beans/*</code-coverage.package.exclude-beanclass>
</properties>
  • Use the property defined in the exclude config

<execution>
   <id>jacoco-check</id>
    <goals>
        <goal>check</goal>
    </goals>
    <configuration>
        <rules>
            <rule>
                <element>PACKAGE</element>
                <excludes>
                    <exclude>${code-coverage.package.exclude-applicationclass}</exclude>
					<exclude>${code-coverage.package.exclude-beanclass}</exclude>
				</excludes>
                <limits>
                    <limit>
                        <counter>LINE</counter>
                        <value>COVEREDRATIO</value>
                        <minimum>${code-coverage.line-covered-ratio.min}</minimum>
                    </limit>
                </limits>
            </rule>
        </rules>
    </configuration>
</execution>	

Works with 0.8.10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: maven type: bug 🐛 Something isn't working
Projects
None yet
Development

No branches or pull requests