Ignoring report generation for specific classes in cobertura maven plugin
Asked Answered
C

5

10

I've been using Cobertura plugin for report generation and instrumentation (with surefire). Here is the issue I am facing:

I am unable to make the plugin ignore report generation for specific classes in my project.

PF below the related excerpt from pom.xml, I have added the ignore tag, but that just ignores instrumentation for the ignored classes.

I want the report for specific projects to not be generated at all.

Firstly, due to my limited knowledge of both Maven and Conberture, I want to know is it possible, and if yes, then what are the changes I need to get done in pom.xml.

pom.xml

<report>
    <!-- other plugins exist but are not important to be listed here I guess -->   
    <plugin>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
            <skipTests>false</skipTests>
            <systemProperties>
                <property>
                <name>net.sourceforge.cobertura.datafile</name>
                <value>target/cobertura/cobertura.ser</value>
                </property>
            </systemProperties>
        </configuration>
    </plugin>
    <!-- The following is the plugin for cobertura, which takes care of integration and report generation-->
    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>cobertura-maven-plugin</artifactId>
        <configuration>
            <check>
                <branchRate>50</branchRate>
                <lineRate>50</lineRate>
                <haltOnFailure>true</haltOnFailure>
                <totalBranchRate>50</totalBranchRate>
                <totalLineRate>50</totalLineRate>
                <packageLineRate>50</packageLineRate>
                <packageBranchRate>50</packageBranchRate>
            </check>
            <instrumentation>
                <ignores>
                  <ignore>deshaw.dportal.alert.*</ignore>
                  <ignore>deshaw.dportal.atc.*</ignore>
                  <ignore>deshaw.dportal.basket.*</ignore>
                  <ignore>deshaw.dportal.fcs.*</ignore>
                  <ignore>deshaw.dportal.event.*</ignore>
                  <ignore>deshaw.dportal.filings.*</ignore>
                  <ignore>deshaw.dportal.glg.*</ignore>
                  <ignore>deshaw.dportal.icp.*</ignore>
                </ignores>
            </instrumentation>
        </configuration>
    </plugin>
</report>

Edit:

This my directory structure:

module
|
|-apps
|    |-alert
|    |    |-src
|    |    |-target
|    |    |-pom.xml
|    |-------------------
|    |-company
|    |    |-src
|    |    |-target
|    |    |-pom.xml
|-----------------------
|-jobs
|    |-job1
|    |    |-src
|    |    |-target
|    |    |-pom.xml
|    |-job2
|    |    |-src
|    |    |-target
|    |    |-pom.xml

I tried the following in module/pom.xml

<instrumentation>
    <excludes>
        <exclude>**/apps/*.*</exclude>
    </excludes>
</instrumentation>

I still get the reports being generated in both the alerts and company directory.

Probably the exclude regex is not right?

Clawson answered 7/3, 2011 at 9:27 Comment(0)
C
4

Cobertura maven plugin does not respect exclusion and ignoring for report generation.It does so for instrumentation though.

Known bug reported at : http://jira.codehaus.org/browse/MCOBERTURA-52

Clawson answered 15/3, 2011 at 5:52 Comment(3)
I am looking into this issue myself. And its wildly annoying because i get a lot of coverage that is not ignored. Any know workarounds?Dody
The only possible workaround I have got till now is , including the plugin in the child POM's , for children you want the report generated.Other than that, no other feasible way to get this done AFAIK.Clawson
This bug has now been recently fixed in version 2.5.2 of the cobertura maven pluginSyndrome
T
4

You can exclude classes from your cobertura report by moving the <plugin> block from the <reporting> block to your <build> block in your pom.xml.

Thermodynamics answered 18/10, 2011 at 13:14 Comment(0)
P
3

I had a similar problem and found a very helpful tutorial: http://www.java-tutorial.ch/software-testing/maven-cobertura

The solution is quite close to the answer that rdvdijk posted. The plugin information should be in the build section as well as in the reporting section. But the exclude information should be placed in the build section of the pom.

Photosensitive answered 28/12, 2012 at 10:48 Comment(2)
plz elaborate more about anything that you are posting in external link.Doit
You link is dead now :(Churchyard
H
1

Use excludes i.o. ignores.
This is how I exclude specific classes from cobertura:

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.4</version>
<configuration>
    <instrumentation>
        <excludes>
            <exclude>com/bnpp/ecom/**/*Test.class</exclude>
            <exclude>com/lrc/web/WicketApplication.class</exclude>
            <exclude>com/lrc/service/HeartBeatWebServiceMock.class</exclude>
        </excludes>
    </instrumentation>
</configuration>

greetz,
Stijn

Hoye answered 7/3, 2011 at 14:42 Comment(5)
Tried that too.It does not seem to exclude at all.Updating my post to include the changes I tried.Clawson
Did you try specifying the version of the plugin?Hoye
No.Should that make a difference?Clawson
Try it to find out, that's the only difference I see between your config and mine, your regex seems ok.Hoye
I dug a bit deeper and came to know, that the exclusion and instrumentation only works for instrumentation and not report generation.Have posted a link , in the answer.Clawson
I
0

I could successfully generate a cobertura coverage report by ignoring the *Test files from the project after changing the cobertura-maven-plugin version from 2.6 to 2.4 (as mentioned by Stjin geukens in the above comments).

Please find the complete maven plugin details below:

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>cobertura-maven-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <instrumentation>
                        <excludes>
                            <exclude>com/services/impl/*Test.class</exclude>
                            <exclude>com/exceptions/*Test.class</exclude>
                            <exclude>com/services/*Test.class</exclude>
                            <exclude>com/utils/*Test.class</exclude>
                        </excludes>
                    </instrumentation>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>cobertura</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

P.S: I am not sure what is the issue with 2.6 version of the plugin

Intricacy answered 1/9, 2015 at 19:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.