4

I have a Java project build with Maven analyzed with SonarQube. Each project consists of a couple of Maven modules, let's say:

  • org.acme.module - API
  • org.acme.module.demo - a small demo application demonstrating the features of this module
  • org.acme.module.doc - documentation for developers
  • org.acme.module.it - integration tests

In an ideal world I'd want to analyze the code quality of all of these modules, but calculate the test coverage only for the API.

However I could not find a way to disable entire projects from the code coverage (sonar.coverage.exclusions only filters the class name, and some of these modules share a package with the API), so now I'm trying to disable these modules from Sonar.

I tried:

<properties>
    <sonar.skippedModules>org.acme.module.demo,org.acme.module.doc,org.acme.module.it</sonar.skippedModules>
</properties>

Which works, but is a lot of work, since I have hundreds of these projects.

<properties>
    <sonar.skip>true</sonar.skip>
</properties>

Works too, but I have to define it similarly for every single sub-module. Also, now Sonar won't analyze the files, which is bad for obvious reasons.

I'd rather have something like <excludedModules>*demo*,*doc*,*it*,<excludedModules> which I could define once in the parent pom.xml and use in all these modules.

This answer states:

You could also do this from the sonar admin page as documented in the Skipping Modules section here.

I was so happy for a moment until I realized the SonarQube documentation does not contain the "Skipping Modules" section anymore. Or maybe it was moved and I just can't find it.

How do I skip the code coverage analysis in multiple modules while still running other Sonar tests?

Or if that's not possible, how to skip these modules in Sonar in a generic way?

G. Ann - SonarSource Team
  • 22,346
  • 4
  • 40
  • 76
Stefan S.
  • 3,950
  • 5
  • 25
  • 77

2 Answers2

1

Login as administrator

Go to your projects, and you should see an Administration tab. Then go to Analysis Scope, then in coverage exclusions add your exclusions:

  • src/main/java/org/acme/module/demo/**

enter image description here

Sydney
  • 11,964
  • 19
  • 90
  • 142
  • The IT module has the exact same packages as the bundle it tests, so that won't work. – Stefan S. Jul 09 '18 at 07:18
  • By convention your tests should be under `src/test/java` and not in a specific module. – Sydney Jul 09 '18 at 11:01
  • That's just not true. `src/test/java` is one of many conventions. We are using plug-in and test-fragment since this seems to be the standard for Eclipse development. – Stefan S. Jul 09 '18 at 12:06
1

In all the child/sub module pom you can add something like below to exclude all the files in that module only from coverage analysis. You still will get the rest of the SonarQube analysis for those modules.

 <profiles>
    <profile>
        <id>sonar</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <properties>
            <sonar.coverage.exclusions>
                **/*.*
            </sonar.coverage.exclusions>
        </properties>
    </profile>
    </profiles>
Jeb
  • 11
  • 1