sonar-project.properties is the configuration file SonarScanner CLI reads from a project's root directory. It tells the scanner which project to report to, where the source and test code is, what to exclude, and where to find coverage reports. This page explains the example files embedded above, fixes the outdated and insecure lines in them, and shows how to run an analysis with the file.
What sonar-project.properties does
When you run sonar-scanner in a directory, the scanner looks for sonar-project.properties in that directory and loads every sonar.* key from it as an analysis parameter. The file uses standard Java properties syntax: one key=value per line, # for comments, and commas to separate list values.
The file is read by SonarScanner CLI and by tools that wrap it, such as the SonarQube scan actions for CI systems and the npm scanner. The Maven and Gradle scanners do not read it. Those builds take their properties from pom.xml or build.gradle, and the .NET scanner takes them from command-line arguments.
The gist above contains seven files: a minimal template, a COBOL/Flex/PL/I sample (included twice), a JavaScript/TypeScript project, an Objective-C project that uses a community plugin, and a large real-world C/C++/Java configuration from the SimGrid project on SonarCloud.
Core properties reference
| Property | Purpose | Notes |
|---|---|---|
sonar.projectKey | Unique ID of the project on the server | Required. Allowed characters are letters, digits, -, _, . and :, and the key needs at least one non-digit |
sonar.projectName | Display name in the UI | Defaults to the project key |
sonar.projectVersion | Version label used to group analyses | Optional. Often set from CI, for example -Dsonar.projectVersion=$BUILD_VERSION |
sonar.sources | Comma-separated directories or files that contain main code | Paths are relative to the file's directory. Defaults to . |
sonar.tests | Directories that contain test code | Test files get test-specific rules and are left out of coverage |
sonar.exclusions / sonar.inclusions | Glob patterns that narrow down the main source files | ** matches any number of directories and * matches part of a name |
sonar.test.inclusions / sonar.test.exclusions | Glob patterns that narrow down the test files | Main and test sets must not overlap |
sonar.coverage.exclusions | Files that are analysed but left out of coverage figures | Useful for generated code and bootstrap files |
sonar.cpd.exclusions | Files left out of duplication detection | Used in the SimGrid example for repetitive examples |
sonar.sourceEncoding | Encoding of the source files | Set UTF-8 explicitly so results don't depend on the build machine's locale |
sonar.host.url | Server URL | Better passed from CI or the SONAR_HOST_URL environment variable |
sonar.token | Authentication token | Never commit it. Use the SONAR_TOKEN environment variable |
sonar.organization | Organization key | Used only by SonarCloud, as in the SimGrid example |
sonar.links.homepage, sonar.links.issue, sonar.links.scm | Project links shown in the UI | Optional |
Language-specific keys follow the pattern sonar.<language>.<setting>, for example sonar.javascript.lcov.reportPaths, sonar.java.binaries or sonar.cfamily.gcov.reportsPath. COBOL, PL/I and C/C++/Objective-C analysis come from SonarSource commercial analyzers. They need a SonarQube edition that includes them, or SonarCloud.
Corrected versions of the examples
Minimal template (sonar-project1.properties). The first line of the original reads sonar-project.properties, which is the filename and not a setting. Java properties parsing turns it into a meaningless key with an empty value, so delete it. A clean starting point:
# Must be unique on the SonarQube server
sonar.projectKey=my:project
sonar.projectName=My project
sonar.projectVersion=1.0
# Paths are relative to this file
sonar.sources=.
sonar.sourceEncoding=UTF-8Code language: PHP (php)
JavaScript/TypeScript project (sonar-project-3.properties). The original has two problems. It commits a credential in sonar.login=EBSI_sonar, and its exclusion pattern **/*.spec.js doesn't match the TypeScript test files (*.spec.ts) it treats as tests. In a NestJS-style layout, unit tests sit next to the code in src. They have to be excluded from the main sources and included as tests, or the scanner reports them as main code or refuses to index them twice.
sonar.projectKey=notarisation
sonar.projectName=notarisation
sonar.projectVersion=1.0
sonar.sourceEncoding=UTF-8
# Main code: everything in src except bootstrap and unit tests
sonar.sources=src
sonar.exclusions=**/node_modules/**,src/main.ts,public/**,**/*.spec.ts
# Tests: unit specs inside src plus e2e specs in tests/
sonar.tests=src,tests
sonar.test.inclusions=**/*.spec.ts,**/*.e2e-spec.ts
# Reports produced by the test run (paths relative to this file)
sonar.javascript.lcov.reportPaths=coverage/lcov.info
sonar.testExecutionReportPaths=coverage/sonar-report.xml
# No credentials here: provide SONAR_TOKEN and SONAR_HOST_URL from CICode language: PHP (php)
Note: sonar.testExecutionReportPaths expects SonarQube's generic test execution XML format. Jest doesn't produce it by default, so add a reporter that outputs this format, or remove the line.
Objective-C project (sonar-project-4.properties). This file targets the old community Objective-C plugin, which relied on a run-sonar.sh script and the sonar.objectivec.* keys. Current SonarQube analyses Objective-C with the commercial CFamily analyzer, which ignores those keys and needs build information such as a compilation database. Other outdated lines: sonar.language no longer restricts analysis because SonarQube analyses all languages it finds. sonar.junit.reportsPath was replaced by sonar.junit.reportPaths. sonar.scm.url is not a valid key, so use sonar.links.scm for the repository link.
COBOL/Flex/PL/I sample (sonar-project-2 and -5). The two files are identical. They are a demo that puts several languages in one project. In a real project, keep only the keys for languages you actually have. Check the Flex coverage key against your server version's documentation before relying on it, because Flex coverage support has changed over time.
Ignoring specific rules on specific files
The SimGrid example shows sonar.issue.ignore.multicriteria, which is the file-based way to switch off a rule for matching files. First list some IDs. Then, for each ID, set a ruleKey (the language repository plus the rule ID, or * for any repository) and a resourceKey (a glob for the files):
sonar.issue.ignore.multicriteria=e1,e2
# Allow System.out in the CLI entry point only
sonar.issue.ignore.multicriteria.e1.ruleKey=java:S106
sonar.issue.ignore.multicriteria.e1.resourceKey=src/main/java/com/example/Cli.java
# Ignore 'deprecated code should be removed' in every language
sonar.issue.ignore.multicriteria.e2.ruleKey=*:S1133
sonar.issue.ignore.multicriteria.e2.resourceKey=**/*Code language: PHP (php)
Every ID in the list needs both sub-keys. A missing or misspelled ID means the rule simply stays active, and the scanner doesn't report an error. Add a comment explaining each exclusion, as SimGrid does, so reviewers can see why it exists. For broad policy changes, editing the quality profile on the server is usually cleaner than piling up exclusions in the file.
Running an analysis with the file
- In SonarQube, generate a token (My Account > Security, or a project analysis token).
- Place
sonar-project.propertiesin the repository root and commit it. It contains no secrets. - Run your tests first so the coverage files exist at the paths the file references.
- Export the server URL and token as environment variables, then run the scanner from the directory that contains the file.
export SONAR_HOST_URL="https://sonarqube.example.com"
export SONAR_TOKEN="<your-token>"
# Installed scanner
sonar-scanner
# Or with Docker, mounting the project at /usr/src
docker run --rm \
-e SONAR_HOST_URL -e SONAR_TOKEN \
-v "$PWD:/usr/src" \
sonarsource/sonar-scanner-cli
# Override any property for a single run
sonar-scanner -Dsonar.projectVersion=2.4.0 -Dsonar.verbose=trueCode language: PHP (php)
A successful run ends with lines that mention ANALYSIS SUCCESSFUL and a dashboard URL such as .../dashboard?id=notarisation, followed by EXECUTION SUCCESS. The server then processes the report in the background, so results can take a few seconds to appear.
When the same key is set in more than one place, later sources win. The order, from lowest to highest priority, is: global settings in the UI, project settings in the UI, the scanner's global conf/sonar-scanner.properties, the project's sonar-project.properties, and finally -D arguments on the command line.
Common errors and fixes
| Symptom | Likely cause | Fix |
|---|---|---|
Mandatory property sonar.projectKey is missing | Scanner run from a directory without the file | cd to the file's directory or pass -Dproject.settings=path/to/file |
| 401 / not authorized | Token missing, expired or lacking Execute Analysis permission | Set SONAR_TOKEN and check the token's permissions on the project |
| File can't be indexed twice | sonar.sources and sonar.tests overlap without disjoint inclusions/exclusions | Exclude test patterns from sources and include them in sonar.test.inclusions |
Please provide compiled classes with sonar.java.binaries | Java files found but no compiled output configured | Build first and point sonar.java.binaries to the class directories |
| Coverage shows 0% | Report path wrong or report generated after the scan | Run tests before the scanner and check the path relative to the properties file |
| C/C++/Objective-C analysis fails | No build-wrapper output or compilation database | Generate one and set sonar.cfamily.compile-commands or sonar.cfamily.build-wrapper-output |
Best practices
- Keep secrets out of the file. Inject
SONAR_TOKENfrom your CI secret store. If a token has ever been committed, revoke it. - Set
sonar.sourcesandsonar.testsexplicitly instead of relying on the.default, which picks up build output and vendored code. - Exclude generated, minified and third-party code (
node_modules,dist, vendored libraries) so issues and duplication figures reflect your own code. - Use
sonar.coverage.exclusionsfor code you don't want counted in coverage but still want checked by rules. - Pass values that change on every build, such as version and branch, with
-Dfrom CI instead of editing the file. - Remove keys for languages and plugins you don't use. Old keys left in the file make it harder to see which settings actually apply.
- Check the C/C++ keys against your current SonarQube documentation. Several
sonar.cfamily.*settings in the SimGrid example, such as threads and cache options, have since been deprecated.
For structured hands-on practice with scanners, quality gates and server administration, see the SonarQube Masterclass.
Frequently asked questions
Where should sonar-project.properties be placed?
Put it in the project's root directory, which is where you run sonar-scanner. All paths inside it are relative to the file's location. You can point to a file elsewhere with -Dproject.settings=path/to/file.
Does Maven or Gradle use sonar-project.properties?
No. The SonarScanner for Maven and the SonarScanner for Gradle ignore this file. With those scanners, set properties in pom.xml, build.gradle or on the command line with -D.
Is sonar.login still valid?
Recent SonarQube versions replaced sonar.login with sonar.token for token authentication. Either way, don't put the value in the file. Set the SONAR_TOKEN environment variable instead.
What is the minimum content of sonar-project.properties?
The only required property is sonar.projectKey. In practice you should also set sonar.sources and sonar.sourceEncoding, so the scanner analyses the right files and reads them correctly.
Do command-line -D parameters override the properties file?
Yes. Command-line -D arguments have the highest priority. They override sonar-project.properties, the scanner's global configuration and server-side settings.
Related tutorials
- SonarQube Masterclass: 2-Day Hands-on Training for Developers, DevOps & Administrators
- More Code Quality & Analysis tutorials
- Top 10 Static Code Analysis Tools: Features, Pros, Cons & Comparison
I’m Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms.
I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.
Find Trusted Cardiac Hospitals
Compare heart hospitals by city and services โ all in one place.
Explore Hospitals
One aspect worth expanding on is treating
sonar-project.propertiesas a versioned governance artifact rather than a static configuration file. In larger engineering organizations, teams often struggle with inconsistent exclusions, duplicated coverage settings, and project-specific rule suppressions that gradually erode the effectiveness of Sonar quality gates. It would be useful to discuss patterns such as maintaining shared templates, injecting environment-specific values at pipeline runtime, periodically auditing exclusions, and keeping secrets or tokens entirely outside the properties file. From a DevOps perspective, the long-term goal is not simply to make scans pass, but to ensure that analysis settings remain reproducible, reviewable, and aligned with evolving organizational standards. Teams that treat Sonar configuration as code and continuously refine their quality gates generally avoid the common anti-pattern where developers begin to view static analysis as noisy compliance overhead rather than a trusted engineering feedback mechanism.