# Setting initial scope

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.

{% hint style="info" %}

* Test and source code are distinguished because test files must be excluded from the source-related metrics and different analysis rules are applied to each category.
* Additionally, test code does not count toward your lines of code (LOC) usage in SonarQube accounts and does not count toward coverage (you don’t have to test your test code).
  {% endhint %}

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

* For source code (non-test 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 <a href="#default-initial-scope" id="default-initial-scope"></a>

{% tabs %}
{% tab title="MAVEN" %}
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](/sonarqube-server/2025.4/analyzing-source-code/scanners/sonarscanner-for-maven.md) page.
{% endtab %}

{% tab title="GRADLE" %}
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](/sonarqube-server/2025.4/analyzing-source-code/scanners/sonarscanner-for-gradle.md) page for details about customizing your analysis.
{% endtab %}

{% tab title=".NET" %}
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 scanner](/sonarqube-server/2025.4/analyzing-source-code/scanners/dotnet/configuring.md) page for details about customizing your analysis.
{% endtab %}

{% tab title="OTHER SCENARIOS" %}
In cases other than Maven, Gradle or .NET:

* 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.
  {% endtab %}
  {% endtabs %}

## Setting the initial scope explicitely <a href="#setting-initial-scope-explicitely" id="setting-initial-scope-explicitely"></a>

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

<details>

<summary>Example where an explicit setting of the initial scope is necessary</summary>

We consider the following repository example where the `src` and `test` directories are clearly separated.

<div align="center"><figure><img src="/spaces/KXW79zfYFiA8incTvwZK/files/wLDtbaYixGMwzjTykmGP" alt="When you define the directories containing all source code, and define a separate directory for all of your test code, setting up the analysis scope is clear and straight-forward." width="563"><figcaption></figcaption></figure></div>

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

```css-79elbk
# Define separate root directories for main and test sources
sonar.sources = src
sonar.tests = test
```

</details>

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 Server UI. For more information, see [Analysis parameters](/sonarqube-server/2025.4/analyzing-source-code/analysis-parameters.md).

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](/sonarqube-server/2025.4/analyzing-source-code/analysis-parameters.md) > **Analysis scope**.

{% hint style="warning" %}
The C/C++/Objective-C analyzer doesn’t currently suppot `sonar.tests`. See **Analyzing test files** in [Customizing the analysis](/sonarqube-server/2025.4/analyzing-source-code/languages/c-family/customizing-the-analysis.md).
{% endhint %}

## Related pages <a href="#related-pages" id="related-pages"></a>

* [Excluding from coverage or duplication](/sonarqube-server/2025.4/project-administration/setting-analysis-scope/exclude-from-coverage-duplication.md)
* [Excluding based on path-matching patterns](/sonarqube-server/2025.4/project-administration/setting-analysis-scope/excluding-files-based-on-patterns.md)
* [Excluding based on file extension](/sonarqube-server/2025.4/project-administration/setting-analysis-scope/excluding-based-on-file-extension.md)
* [Applying advanced exclusions](/sonarqube-server/2025.4/project-administration/setting-analysis-scope/advanced-exclusions.md)
* [Other adjustments](/sonarqube-server/2025.4/project-administration/setting-analysis-scope/other-adjustments.md)
* [Verifying analysis scope](/sonarqube-server/2025.4/project-administration/setting-analysis-scope/verifying-analysis-scope.md)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sonarsource.com/sonarqube-server/2025.4/project-administration/setting-analysis-scope/setting-initial-scope.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
