Maven Jacoco Configuration - Exclude classes/packages from report not working

前端 未结 7 2086
傲寒
傲寒 2020-11-28 21:00

I have a maven multi-module project and I\'m using jacoco-maven for code coverage reports. Some classes should not be reported, as they\'re Spring configuration and I\'m not

7条回答
  •  我在风中等你
    2020-11-28 21:59

    Your XML is slightly wrong, you need to add any class exclusions within an excludes parent field, so your above configuration should look like the following as per the Jacoco docs

    
        
            **/*Config.*
            **/*Dev.*
        
    
    

    The values of the exclude fields should be class paths (not package names) of the compiled classes relative to the directory target/classes/ using the standard wildcard syntax

    *   Match zero or more characters
    **  Match zero or more directories
    ?   Match a single character
    

    You may also exclude a package and all of its children/subpackages this way:

    some/package/**/*
    

    This will exclude every class in some.package, as well as any children. For example, some.package.child wouldn't be included in the reports either.

    I have tested and my report goal reports on a reduced number of classes using the above.

    If you are then pushing this report into Sonar, you will then need to tell Sonar to exclude these classes in the display which can be done in the Sonar settings

    Settings > General Settings > Exclusions > Code Coverage

    Sonar Docs explains it a bit more

    Running your command above

    mvn clean verify
    

    Will show the classes have been excluded

    No exclusions

    [INFO] --- jacoco-maven-plugin:0.7.4.201502262128:report (post-test) @ ** ---
    [INFO] Analyzed bundle '**' with 37 classes
    

    With exclusions

    [INFO] --- jacoco-maven-plugin:0.7.4.201502262128:report (post-test) @ ** ---
    [INFO] Analyzed bundle '**' with 34 classes
    

    Hope this helps

提交回复
热议问题