SONAR - How to exclude packages that is defined under "sonar.test"

31,074

Solution 1

You can define exclusions in the Configurations for the project directly in sonar.

exclusions

Solution 2

From the documentation:

Since version 3.3, it is also possible to: Exclude tests file from being analyzed: go to Configuration > Settings > Exclusions and set > the sonar.test.exclusions property

The trick is:

  • sonar.exclusions: excludes files from sources directory (i.e.sonar.sources), it has no effect on tests directory.
  • sonar.test.exclusions: excludes files from tests directory (i.e.sonar.tests), it has no effect on sources directory.

See https://docs.sonarqube.org/display/SONAR/Narrowing+the+Focus

And, Using sonar.test.exclusions with Sonarqube 6.3

Share:
31,074
lwijono
Author by

lwijono

Updated on July 24, 2022

Comments

  • lwijono
    lwijono almost 2 years

    I have a projects in JAVA that I analyze using sonar. Some of the java packages that I have are all under source folder. I also have some test file that I have under a different folders. Now, in Sonar, I organize my projects under a different structure, i.e. for a project "search", I only wants to include "search" package. These exclusion is quite easy to accomplished using sonar.exclusion properties. My question, though, is how about the test? how can I exclude some of the packages? Because from my testing, even though my source and test folder are using the same structure, the test packages are not automatically excluded when I specified "sonar.exclusions".

    my folder structure:

    /src/com/domain/
       -- search/
       -- utils/
       -- pooling/
       -- category/
    
    /test/src/com/domain/
       -- utils/
       -- pooling/
    

    Sonar properties:

    <property name="sonar.sources" value="${path}/src" />
    <property name="sonar.tests" value="${path}/test/src" />
    <property name="sonar.exclusions" value="com/domain/utils/**/*,com/domain/pooling/**/*,com/domain/category/**/*" />
    

    So, I am trying to only include the "search" package. The code above works in a way that it causes SONAR to only analyze my "search" package. This package can be seen in the SONAR "Components" tab. Unfortunately, in addition to the "search" component, I can also see the "util" and "pooling" components. I have done some testing and certain that these two components (utils and pooling) are the result of "sonar.tests" properties. Just a note though, even though "util" and "pooling" shows up in components, SONAR shows zero files under both of them. So going back to my question, is there anyway that I can do to exclude "util" and "pooling" from showing up under "Components"? Maybe using properties (i.e. sonar test exclusions)?

    Btw, I am using SONAR 2.11 and is running under Red Hat linux. I'm using SONAR-TASK 1.2.

    Any help is welcomed and appreciated! Thanks!