Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使Sonar忽略某些类别的codeCoverage度量?_Java_Maven_Sonarqube - Fatal编程技术网

Java 如何使Sonar忽略某些类别的codeCoverage度量?

Java 如何使Sonar忽略某些类别的codeCoverage度量?,java,maven,sonarqube,Java,Maven,Sonarqube,我在Maven有一个声纳剖面图。除了代码覆盖率指标外,其他一切都正常。我想让Sonar只为代码覆盖率指标忽略一些类。我有以下个人资料: 声纳 **/bean/jaxb/** org.apache.maven.plugins maven surefire插件 ${maven.surefire.plugin.version} 真的 **/*套件*.java **/*RemoteTest.java **/*SpringTest.java **/*CamelTest.java **/*Function

我在Maven有一个声纳剖面图。除了代码覆盖率指标外,其他一切都正常。我想让Sonar只为代码覆盖率指标忽略一些类。我有以下个人资料:


声纳
**/bean/jaxb/**
org.apache.maven.plugins
maven surefire插件
${maven.surefire.plugin.version}
真的
**/*套件*.java
**/*RemoteTest.java
**/*SpringTest.java
**/*CamelTest.java
**/*FunctionalTest.java
**/*IntegrationTest.java
**/*DaoBeanTest.java
请帮忙。我试着添加一些类似于

com/qwerty/dw/publisher/Main.class
但这没用

更新

我有一个正确的Cobertura档案。我试图将其添加到声纳剖面图中,但仍然有53%,而不是像Cobertura剖面图中的95%


声纳
**/bean/jaxb/**
科贝图拉
org.apache.maven.plugins
maven surefire插件
${maven.surefire.plugin.version}
真的
**/*套件*.java
**/*RemoteTest.java
**/*SpringTest.java
**/*CamelTest.java
**/*FunctionalTest.java
**/*IntegrationTest.java
**/*DaoBeanTest.java
org.codehaus.mojo
cobertura maven插件
${cobertura.maven.plugin.version}
com/qwerty/dw/dao/*
com/qwerty/dw/domain/*
com/qwerty/dw/beans/**/*
com/qwerty/dw/daemon/exception/*
com/qwerty/dw/daemon/Main.class
com/qwerty/dw/sink/Main.class
com/qwerty/dw/publisher/Main.class
com/qwerty/dw/publisher/dao/*
com/qwerty/dw/publisher/domain/*
html
真的
真的
60
60
60
60
清洁的
检查

我想你正在寻找这个答案中描述的解决方案
请记住,如果您使用的是Sonar 3.2,您必须指定您的覆盖工具是cobertura而不是jacoco(默认),因为jacoco还不支持此类功能。有时,Clover配置为为为所有非测试代码提供代码覆盖报告。如果希望覆盖这些首选项,可以使用配置元素排除和包含要检测的源文件:

<plugin>
    <groupId>com.atlassian.maven.plugins</groupId>
    <artifactId>maven-clover2-plugin</artifactId>
    <version>${clover-version}</version>
    <configuration> 
        <excludes> 
            <exclude>**/*Dull.java</exclude> 
        </excludes> 
    </configuration>
</plugin>

com.atlassian.maven.plugins
maven-clover2-plugin
${clover版本}
**/*Dull.java
此外,还可以包括以下声纳配置:

<properties>
    <sonar.exclusions>
        **/domain/*.java,
        **/transfer/*.java
    </sonar.exclusions>
</properties> 

**/domain/*.java,
**/transfer/*.java
对我来说,这很有效(基本上是
pom.xml
级别的全局属性):


**/名称*.java
根据:

看起来您可以以“.java”或“*”结尾

获取您感兴趣的java类


对于jacoco:使用以下属性:

<properties>
    <sonar.exclusions>**/Name*.java</sonar.exclusions>
</properties>
-Dsonar.jacoco.excludes=**/*View.java

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


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


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

使用sonar scanner for swift时,请在sonar-project.properties中使用sonar.coverage.Exclutions以排除任何仅用于代码覆盖的文件。如果还想从分析中排除文件,可以使用sonar.Exclutions。这在斯威夫特对我很有效

sonar.coverage.exclusions=**/*ViewController.swift,**/*Cell.swift,**/*View.swift
相应地,根据文件BE 7.1

sonar.Exclutions-要删除的文件路径模式的逗号分隔列表 排除在分析之外 声纳。覆盖范围。排除范围-逗号分隔 要从覆盖范围中排除的文件路径模式列表 计算

本文给出了一些关于如何创建路径模式的示例

# Exclude all classes ending by "Bean"
# Matches org/sonar.api/MyBean.java, org/sonar/util/MyOtherBean.java, org/sonar/util/MyDTO.java, etc.
sonar.exclusions=**/*Bean.java,**/*DTO.java

# Exclude all classes in the "src/main/java/org/sonar" directory
# Matches src/main/java/org/sonar/MyClass.java, src/main/java/org/sonar/MyOtherClass.java
# But does not match src/main/java/org/sonar/util/MyClassUtil.java
sonar.exclusions=src/main/java/org/sonar/*

# Exclude all COBOL programs in the "bank" directory and its sub-directories
# Matches bank/ZTR00021.cbl, bank/data/CBR00354.cbl, bank/data/REM012345.cob
sonar.exclusions=bank/**/*

# Exclude all COBOL programs in the "bank" directory and its sub-directories whose extension is .cbl
# Matches bank/ZTR00021.cbl, bank/data/CBR00354.cbl
sonar.exclusions=bank/**/*.cbl
如果您在项目中使用Maven,可以像下面这样传递Maven命令行参数,例如
-Dsonar.coverage.exclusions=***/config/*,***/model/*

我在明确排除单个类时遇到了问题。以下是我的观察:

**/*GlobalExceptionhandler.java - not working for some reason, I was expecting such syntax should work
com/some/package/name/GlobalExceptionhandler.java - not working
src/main/java/com/some/package/name/GlobalExceptionhandler.java - good, class excluded explicitly without using wildcards

我不得不挣扎一点,但我找到了解决办法,我补充道

-Dsonar.coverage.exclusions=**/*.* 
那封面呢
`-Dsonar.coverage.exclusions=**/exceptions/**/*.*` 
-Dsonar.coverage.exclusions=**/exceptions/*.*
<plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.8.6</version>
                <executions>
                    <execution>
                        <id>pre-test</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                        <configuration>
                            <propertyName>jacocoArgLine</propertyName>
                            <destFile>${project.test.result.directory}/jacoco/jacoco.exec</destFile>
                        </configuration>
                    </execution>
                    <execution>
                        <id>post-test</id>
                        <phase>test</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                        <configuration>
                            <dataFile>${project.test.result.directory}/jacoco/jacoco.exec</dataFile>
                            <outputDirectory>${project.test.result.directory}/jacoco</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
                <configuration>
                    <excludes>
                        <exclude>**/GlobalExceptionHandler*.*</exclude>
                        <exclude>**/ErrorResponse*.*</exclude>
                    </excludes>
                </configuration>
            </plugin>
    <sonar.exclusions> **/*GlobalExceptionHandler*.*, **/*ErrorResponse*.</sonar.exclusions>
        <sonar.coverage.exclusions> **/*GlobalExceptionHandler*.*, **/*ErrorResponse*.* </sonar.coverage.exclusions>