How to make Sonar ignore some classes for codeCoverage metric?

后端 未结 8 1926
花落未央
花落未央 2020-12-08 09:18

I have a Sonar profile in Maven. Everything works fine except the code coverage metric. I want to make Sonar ignore some classes only for the code coverage metric. I have th

相关标签:
8条回答
  • 2020-12-08 09:38

    For jacoco: use this properties:

    -Dsonar.jacoco.excludes=**/*View.java
    
    0 讨论(0)
  • 2020-12-08 09:40

    I think you 're looking for the solution described in this answer Exclude methods from code coverage with Cobertura Keep in mind that if you're using Sonar 3.2 you have specify that your coverage tool is cobertura and not jacoco ( default ), which doesn't support this kind of feature yet

    0 讨论(0)
  • 2020-12-08 09:42

    I had to struggle for a little bit but I found a solution, I added

    -Dsonar.coverage.exclusions=**/*.* 
    

    and the coverage metric was cancelled from the dashboard at all, so I realized that the problem was the path I was passing, not the property. In my case the path to exclude was java/org/acme/exceptions, so I used :

    `-Dsonar.coverage.exclusions=**/exceptions/**/*.*` 
    

    and it worked, but since I don't have sub-folders it also works with

    -Dsonar.coverage.exclusions=**/exceptions/*.*
    
    0 讨论(0)
  • 2020-12-08 09:43

    For me this worked (basically pom.xml level global properties):

    <properties>
        <sonar.exclusions>**/Name*.java</sonar.exclusions>
    </properties>
    

    According to: http://docs.sonarqube.org/display/SONAR/Narrowing+the+Focus#NarrowingtheFocus-Patterns

    It appears you can either end it with ".java" or possibly "*"

    to get the java classes you're interested in.

    0 讨论(0)
  • 2020-12-08 09:44

    When using sonar-scanner for swift, use sonar.coverage.exclusions in your sonar-project.properties to exclude any file for only code coverage. If you want to exclude files from analysis as well, you can use sonar.exclusions. This has worked for me in swift

    sonar.coverage.exclusions=**/*ViewController.swift,**/*Cell.swift,**/*View.swift
    
    0 讨论(0)
  • 2020-12-08 09:56

    Sometimes, Clover is configured to provide code coverage reports for all non-test code. If you wish to override these preferences, you may use configuration elements to exclude and include source files from being instrumented:

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

    Also, you can include the following Sonar configuration:

    <properties>
        <sonar.exclusions>
            **/domain/*.java,
            **/transfer/*.java
        </sonar.exclusions>
    </properties> 
    
    0 讨论(0)
提交回复
热议问题