Cobertura excludes not working in multi-module Maven 3 project

3.4k Views Asked by At

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.

1

There are 1 best solutions below

1
On BEST ANSWER

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>