简体   繁体   中英

Skip Code Coverage For Modules in SonarQube

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?

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/**

在此处输入图片说明

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM