Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Next »

It is very important that SonarQube does not provide too much noise. Otherwise development teams would push back the tool.

That's why configuring Exclusions is an important step when setting up a project into SonarQube.

Here are a few use cases you can achieve with exclusions:

  • Exclude generated files => Indeed, it is useless to analyze such code as you don't have any way to fix issues that would be raised
  • Don't check some rules on specific objects => For example, you may to use hard coded value to define some types of objects, but you still want to forbid the usage of hardcoded value everywhere else

Excluding specific files from being analyzed

Source Directory

File extension

Each language plugin offers a way to restrict analysis to files matching a set of extensions.

 

It is possible to exclude files from being analyzed. Go to Configuration > Settings > Exclusions and set the sonar.exclusions property.

Since version 3.3, it is also possible to:
  • Exclude tests file from being analyzed: go to Configuration > Settings > Exclusions and set the sonar.tests.exclusions property
  • Set global exclusions that will apply to all the projects: go to Settings > General Settings > Exclusions and set the sonar.global.exclusions and sonar.global.tests.exclusions properties.

 

Coding rules

Icon

If you want to exclude source code from being check against some coding rules, you can have a look at the Switch Off Violations plugin.

Since version 3.5, it is also possible to:

  • Set the files to be analyzed through the sonar.inclusions and sonar.test.inclusions properties. In this case, only these specific files will be analyzed.
  • Exclude some files from being checked against duplications. To do so, set the sonar.cpd.exclusions property (Configuration > Settings > Duplications).

There are two different ways to exclude/include files:

  • Fully qualified name of the component (see red frames below):

    For Java only, replace '.' package separator by '/' and add '.java' extension.

    Examples



  • Absolute path:

    Examples

Full documentation is available directly in the SonarQube web interface (Configuration > Settings > Exclusions).

Excluding coding rule checks on specific objects

 

 

Excluding specific files to be checked for duplications

 

Excluding specific files to be taken into account for code coverage computation

  • No labels