简体   繁体   English

SonarQube中模块的跳过代码覆盖率

[英]Skip Code Coverage For Modules in SonarQube

I have a Java project build with Maven analyzed with SonarQube. 我有一个使用SonarQube分析的Maven构建的Java项目。 Each project consists of a couple of Maven modules, let's say: 每个项目都包含几个Maven模块,例如:

  • org.acme.module - API org.acme.module -API
  • org.acme.module.demo - a small demo application demonstrating the features of this module org.acme.module.demo一个演示该模块功能的小型演示应用程序
  • org.acme.module.doc - documentation for developers org.acme.module.doc开发人员文档
  • org.acme.module.it - integration tests org.acme.module.it集成测试

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. 在理想的情况下,我想分析所有这些模块的代码质量,但只计算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. 但是我找不到从代码覆盖范围禁用整个项目的方法( sonar.coverage.exclusions仅过滤类名,并且其中一些模块与API共享一个包),所以现在我尝试禁用这些模块来自声纳。

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. 而且,现在Sonar不会分析文件,这很明显是有原因的。

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. 我宁愿有类似<excludedModules>*demo*,*doc*,*it*,<excludedModules> ,我可以在父pom.xml中定义一次并在所有这些模块中使用。

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. 直到我意识到SonarQube文档不再包含“跳过模块”部分,我才感到非常高兴。 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? 如何在仍然运行其他Sonar测试的同时跳过多个模块中的代码覆盖率分析?

Or if that's not possible, how to skip these modules in Sonar in a generic way? 还是如果不可能,如何以一种通用的方式在Sonar中跳过这些模块?

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: 然后转到Analysis Scope,然后在coverage排除项中添加排除项:

  • src/main/java/org/acme/module/demo/** 的src / main / JAVA /组织/ ACME /模块/演示/ **

在此处输入图片说明

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. 在所有子/子模块pom中,您可以添加以下内容,以仅从覆盖率分析中排除该模块中的所有文件。 You still will get the rest of the SonarQube analysis for those modules. 您仍将获得这些模块的SonarQube分析的其余部分。

 <profiles>
    <profile>
        <id>sonar</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <properties>
            <sonar.coverage.exclusions>
                **/*.*
            </sonar.coverage.exclusions>
        </properties>
    </profile>
    </profiles>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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