gpt4 book ai didi

java - 如何让 Sonar 忽略 codeCoverage 指标的某些类?

转载 作者:IT老高 更新时间:2023-10-28 20:50:46 24 4
gpt4 key购买 nike

我在 Maven 中有一个 Sonar 配置文件。除了代码覆盖率指标外,一切正常。我想让 Sonar 仅针对代码覆盖率指标忽略某些类。我有以下个人资料:

<profile>
<id>sonar</id>
<properties>
<sonar.exclusions>**/beans/jaxb/**</sonar.exclusions>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.plugin.version}</version>
<configuration>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<excludes>
<exclude>**/*Suite*.java</exclude>
<exclude>**/*RemoteTest.java</exclude>
<exclude>**/*SpringTest.java</exclude>
<exclude>**/*CamelTest.java</exclude>
<exclude>**/*FunctionalTest.java</exclude>
<exclude>**/*IntegrationTest.java</exclude>
<exclude>**/*DaoBeanTest.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</profile>

请帮忙。我尝试添加类似

的内容
<exclude>com/qwerty/dw/publisher/Main.class</exclude>

但没用

更新

我有正确的 Cobertura 个人资料。我尝试将其添加到 Sonar 配置文件中,但我仍然有 53% 而不是像 Cobertura 配置文件中那样的大约 95%

<profile>
<id>sonar</id>
<properties>
<sonar.exclusions>**/beans/jaxb/**</sonar.exclusions>
<sonar.core.codeCoveragePlugin>cobertura</sonar.core.codeCoveragePlugin>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.plugin.version}</version>
<configuration>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<excludes>
<exclude>**/*Suite*.java</exclude>
<exclude>**/*RemoteTest.java</exclude>
<exclude>**/*SpringTest.java</exclude>
<exclude>**/*CamelTest.java</exclude>
<exclude>**/*FunctionalTest.java</exclude>
<exclude>**/*IntegrationTest.java</exclude>
<exclude>**/*DaoBeanTest.java</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>${cobertura.maven.plugin.version}</version>
<configuration>
<instrumentation>
<excludes>
<exclude>com/qwerty/dw/dao/*</exclude>
<exclude>com/qwerty/dw/domain/*</exclude>
<exclude>com/qwerty/dw/beans/**/*</exclude>
<exclude>com/qwerty/dw/daemon/exception/*</exclude>
<exclude>com/qwerty/dw/daemon/Main.class</exclude>
<exclude>com/qwerty/dw/sink/Main.class</exclude>
<exclude>com/qwerty/dw/publisher/Main.class</exclude>
<exclude>com/qwerty/dw/publisher/dao/*</exclude>
<exclude>com/qwerty/dw/publisher/domain/*</exclude>
</excludes>
</instrumentation>
<formats>
<format>html</format>
</formats>
<aggregate>true</aggregate>
<check>
<haltOnFailure>true</haltOnFailure>
<branchRate>60</branchRate>
<lineRate>60</lineRate>
<totalBranchRate>60</totalBranchRate>
<totalLineRate>60</totalLineRate>
</check>
</configuration>
<executions>
<execution>
<goals>
<goal>clean</goal>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>

最佳答案

在撰写本文时(使用 SonarQube 4.5.1),要设置的正确属性是 sonar.coverage.exclusions,例如:

<properties>
<sonar.coverage.exclusions>foo/**/*,**/bar/*</sonar.coverage.exclusions>
</properties>

这似乎与之前的几个版本有所不同。请注意,这仅将给定类从覆盖率计算中排除。计算所有其他指标和问题。

为了找到您的 SonarQube 版本的属性名称,您可以尝试转到 SonarQube 实例的 General Settings 部分并查找 Code Coverage 项(在 SonarQube 4.5.x 中,常规设置 → 排除 → 代码覆盖率)。在输入字段下方,它给出了上面提到的属性名称(“Key: sonar.coverage.exclusions”)。

关于java - 如何让 Sonar 忽略 codeCoverage 指标的某些类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12135939/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com