Start Free
SonarQube Community Build | Project administration | Setting analysis scope | Setting initial scope

Setting the initial analysis scope of your project

On this page

The initial analysis scope of a project must be defined for source code (also called main code) on one side and for test code on the other side. 

The initial scope of a project is controlled by the following sonar properties:

  • For source code (main code): sonar.sources
  • For test code: sonar.tests

which define that: 

  • Files outside the initial scope will not be analyzed at all.
  • Files within the initial scope will be analyzed unless excluded by further adjustments.

Each project's initial scope is defined by default. If it doesn't suit you, you can set it explicitly. 

Default initial scope

If you are analyzing code using the SonarScanner for Maven, the sonar.sources and sonar.tests parameters are automatically determined based on information in your project configuration. You do not have to explicitly set the parameters. 

If you do explicitly set the parameters, for example in your pom.xml file, they will override the automatically determined values.

See also the Adjusting the analysis scope article on the SonarScanner for Maven page.

If you are analyzing code using the SonarScanner for Gradle, the sonar.sources and sonar.tests parameters are automatically determined based on information in your project configuration. You do not have to explicitly set the parameters. 

If you do explicitly set the parameters, for example in your gradle.properties file, they will override the automatically determined values.

See also the SonarScanner for Gradle page for details about customizing your analysis.

The sonar.sources and sonar.tests parameters are not compatible with the SonarScanner for .NET. They are automatically detected and cannot be changed.

If you are analyzing code using the SonarScanner for .NET v8.0.1 or earlier, the sonar.sources and sonar.tests parameters are automatically determined based on information in your project configuration. The SonarScanner for .NET does not support user-defined values for sonar.sources and sonar.tests

See the Configuring the SonarScanner for .NET page for details about customizing your analysis.

In cases other than Maven, Gradle or .NET (including both CI-based analysis and automatic analysis):

  • By default, sonar.sources is set to the value of sonar.projectBaseDir property, which is, by default, the current working directory (i.e.: the path .).
  • sonar.tests defaults to null, meaning there is assumed to be no test code.

Setting the initial scope explicitely

If the default initial scope is not suitable (see example below), you must change it. 

Example where an explicit setting of the initial scope is necessary

We consider the following repository example where the main and test sources are clearly separated. 

If the SonarScanner CLI is used, the corresponding code below can be used in the sonar-project.properties file to change the default initial scope (for an integrated scanner, the configuration can be done in the build’s project definition file).

# Define separate root directories for main and test sources
sonar.sources = main/
sonar.tests = test/

The parameters sonar.sources and sonar.tests are only settable by key on the CI/CD host (mainly in configuration files or on the command line), not in the SonarQube Community Build UI. For more information, see Analysis parameters.

To set sonar.sources and sonar.tests:

  • Use a comma-delimited list of directories or files.
  • The entries in the list are simple paths. Wildcard patterns are not allowed.
  • A directory in the list means that all analyzable files and directories recursively below it are included. An individual file in the list means that the file is included.
  • The paths are interpreted relative to the project base directory which is defined through the sonar.projectBaseDir property. In most cases, this is the root directory of the project. For more information about this property, see Analysis parameters > Analysis scope.

Was this page helpful?

© 2008-2025 SonarSource SA. All rights reserved. SONAR, SONARSOURCE, SONARQUBE, and CLEAN AS YOU CODE are trademarks of SonarSource SA.

Creative Commons License