0

I have a multi-module Maven 3 project. We are using Cobertura as our code coverage tool, but the excludes tag is not working. We have some bad tests from a package we inherited from another team, but need to consume.

The structure is as follows:

<module1>
    .../com/aaaa/...
<module2>
    .../com/aaaa/...
<module3>
    .../com/aaaa/...
...
<moduleN>
    packages with .../com/xx/... WE WANT TO EXCLUDE
    pacakges with .../com/aaaa/... WE WANT TO STILL INCLUDE
parent-pom.xml

Our parent POM is configured as such:

<build>
    ...
    <plugins>
        <other plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>cobertura-maven-plugin</artifactId>
        <version>2.6</version>
        <configuration>
            <aggregate>true</aggregate>
            <outputDirectory>coverageReports</outputDirectory>
            <instrumentation>
                <excludes>
                <exclude>**/com/xx/**/*</exclude>
                </excludes>
            </instrumentation>
        /configuration>
        </plugin>
</plugins>
</build>

<reporting>
    <plugins>
        <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>cobertura-maven-plugin</artifactId>
        <version>2.6</version>
        <configuration>
            <aggregate>true</aggregate>
            <outputDirectory>coverageReports</outputDirectory>
        </configuration>
        </plugin>
    </plugins>
</reporting>

I've tried a lot of various configurations, including:

  1. Excluding the test/com/xx files as well
  2. Adding the exclusion pattern to ignore
  3. Setting exclude in the reporting AND build section
  4. Multiple permutations of the exclude file pattern, including being more implicit

Any thoughts? I've had some other build engineers look at my various POM configurations and it always seems valid, but we never get accurate reports.

Tunaki
  • 132,869
  • 46
  • 340
  • 423
user3076199
  • 23
  • 2
  • 4

1 Answers1

2

Put the exclude configuration into the pom.xml file of moduleN that you want to do the exclusions from:

  <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>cobertura-maven-plugin</artifactId>
    <version>2.6</version>
    <configuration>
      <instrumentation>
        <excludes>
          <exclude>com/aaa/**/*.class</exclude>
          <exclude>com/xxx/**/*.class</exclude>
        </excludes>
      </instrumentation>
    </configuration>
  </plugin>
John Farrelly
  • 7,289
  • 9
  • 42
  • 52
  • 1
    I am facing similar issue. but even after adding exclude and ignore, i am still finding excluded classes in report of cobertura. Also tried having same plugin in and section in pom.xml but in vain. please help. – DecKno Oct 19 '16 at 13:04