Setting the analysis scope of your project
There are many cases where you do not want to analyze every aspect of every source file in your project. For example, your project may contain generated code, source code from libraries, or intentionally duplicated code.
In such cases, it makes sense to skip some or all aspects of analysis for these files, thus removing noise and narrowing the focus to issues that really matter. To help narrow the focus, SonarQube Server gives you several options to precisely configure what will be analyzed and how.
- With the Enterprise plan, your organization admin can set up default analysis scope adjustments for all projects of the organization. You can change them.
- The new code definition of your project has an impact on the analysis scope. For more information, see Defining new code.
- Subscription plans are tiered according to the total number of lines of code (LOC) analyzed in your private repositories. This LOC calculation does not count code in excluded files (nor does it count blank lines or comments). For more details, see LOC-based pricing in Subscription plans.
Step 1: Check your project's default initial scope
Check your project's default initial scope. If it doesn't suit you, you must set the initial scope explicitly.
See Setting the initial analysis scope of a project.
Step 2: If necessary, adjust the initial scope
You may have to adjust the initial scope mainly in the following cases:
- If the directory structure of your project does not cleanly separate source code from test code at the top level. In that case, you can exclude files based on path-matching patterns or file extensions by programming language.
- To exclude specific files from duplication check.
- To exclude specific files from coverage reporting.
You can also perform other exclusions, such as excluding files over a certain size limit or disabling the SCM’s file ignore patterns. In very few situations, you may have to use advanced exclusion features.
To exclude code from the analysis, you define exclusion parameters for the project. You can define most exclusion parameters:
- In SonarQube Cloud UI
This requires that you have the Administer permission for the project.
When possible, it is the recommended method since it allows a centralized, reliable, and user-friendly configuration. - On the CI/CD host
With this method, you configure the respective sonar properties on the CI/CD host. Note that a parameter set through this method has precedence over any UI setting of the same parameter.
See:
- Excluding specific files from your project's code coverage analysis or duplication check
- Excluding files from your project analysis based on path-matching patterns
- Excluding files from your project analysis based on file extension
- Applying advanced exclusions to your project analysis
- Performing other analysis scope adjustments
Step3: Verify the settings
After the first project analysis run, you can verify that the configured analysis scope is correct. See Verifying the analysis scope of a project.
Was this page helpful?