โ˜• XOPSSCHOOL โ€” LEARNING MADE AFFORDABLE
Build the Skills Your Next Career Move Demands.
For the Price of One Coffee a Month.
Why spend hundreds on individual courses? Unlock an entire year of technical learning with one Coffee Pass.
US$4.90 /month
US$58.80/year
โ‚น499 + GST/month
โ‚น5,988 + GST/year
โ‚ฌ4.90 /month
โ‚ฌ58.80/year
12 Months of Access • Billed Annually • No Automatic Renewal
DevOps • Cloud • SRE • Kubernetes • Terraform • DevSecOps • AI • AIOps • MLOps • LLMOps • FinOps • GitOps • Platform Engineering & Much More
192
Premium Courses
1,085
Video Sessions
99
Ops Disciplines
86
Tool Courses
340
Assignments
227
Quizzes
โœ“ QR-Verifiable Certificates   โœ“ Learn at Your Own Pace   โœ“ Hands-on Learning   โœ“ New Courses Included
Learn from real-world, instructor-led video sessions by
Rajesh Kumar
Principal Architect • Trainer • Mentor • 15+ Years of Industry Experience
โ˜• Get My Coffee Pass โ€” Start Learning Today →
One Payment. Every Premium Course. One Full Year.
The best investment you can make is in the person you are becoming.

Example of sonar-project.properties file

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

PropertyPurposeNotes
sonar.projectKeyUnique ID of the project on the serverRequired. Allowed characters are letters, digits, -, _, . and :, and the key needs at least one non-digit
sonar.projectNameDisplay name in the UIDefaults to the project key
sonar.projectVersionVersion label used to group analysesOptional. Often set from CI, for example -Dsonar.projectVersion=$BUILD_VERSION
sonar.sourcesComma-separated directories or files that contain main codePaths are relative to the file's directory. Defaults to .
sonar.testsDirectories that contain test codeTest files get test-specific rules and are left out of coverage
sonar.exclusions / sonar.inclusionsGlob patterns that narrow down the main source files** matches any number of directories and * matches part of a name
sonar.test.inclusions / sonar.test.exclusionsGlob patterns that narrow down the test filesMain and test sets must not overlap
sonar.coverage.exclusionsFiles that are analysed but left out of coverage figuresUseful for generated code and bootstrap files
sonar.cpd.exclusionsFiles left out of duplication detectionUsed in the SimGrid example for repetitive examples
sonar.sourceEncodingEncoding of the source filesSet UTF-8 explicitly so results don't depend on the build machine's locale
sonar.host.urlServer URLBetter passed from CI or the SONAR_HOST_URL environment variable
sonar.tokenAuthentication tokenNever commit it. Use the SONAR_TOKEN environment variable
sonar.organizationOrganization keyUsed only by SonarCloud, as in the SimGrid example
sonar.links.homepage, sonar.links.issue, sonar.links.scmProject links shown in the UIOptional

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

  1. In SonarQube, generate a token (My Account > Security, or a project analysis token).
  2. Place sonar-project.properties in the repository root and commit it. It contains no secrets.
  3. Run your tests first so the coverage files exist at the paths the file references.
  4. 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

SymptomLikely causeFix
Mandatory property sonar.projectKey is missingScanner run from a directory without the filecd to the file's directory or pass -Dproject.settings=path/to/file
401 / not authorizedToken missing, expired or lacking Execute Analysis permissionSet SONAR_TOKEN and check the token's permissions on the project
File can't be indexed twicesonar.sources and sonar.tests overlap without disjoint inclusions/exclusionsExclude test patterns from sources and include them in sonar.test.inclusions
Please provide compiled classes with sonar.java.binariesJava files found but no compiled output configuredBuild first and point sonar.java.binaries to the class directories
Coverage shows 0%Report path wrong or report generated after the scanRun tests before the scanner and check the path relative to the properties file
C/C++/Objective-C analysis failsNo build-wrapper output or compilation databaseGenerate one and set sonar.cfamily.compile-commands or sonar.cfamily.build-wrapper-output

Best practices

  • Keep secrets out of the file. Inject SONAR_TOKEN from your CI secret store. If a token has ever been committed, revoke it.
  • Set sonar.sources and sonar.tests explicitly 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.exclusions for 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 -D from 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

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services โ€” all in one place.

Explore Hospitals

Related Posts

How to Migrate Sonarqube from H2 to Postgresql?

This page shows how to move SonarQube off its embedded H2 database and onto PostgreSQL: run PostgreSQL in Docker, point sonar.properties at it, set the kernel limits…

Read More

Gitlab Tutorials: CI for automation and .Net Framework Sonarqube Codecoverage

This page shows how to build a .NET Framework project in GitLab CI, run its unit tests with code coverage, and send the results to SonarQube or…

Read More

Sonar Maven Plugin 1.0-beta-2: What Changed for Archiva/Nexus-Based Builds

This historical release note introduced simpler Sonar Maven Plugin behavior when using repository managers like Archiva or Nexus. Hereโ€™s what changed from beta-1, how compatibility works with Sonar versions, and how to validate legacy CI behavior.

Read More

Sonar Maven Plugin 1.0-beta-2: What Changed and How to Configure Legacy Builds

This update from the Mojo team simplified Sonar Maven Plugin configuration when using repository managers like Archiva or Nexus. Hereโ€™s a clear breakdown of compatibility, behavior differences from beta-1, and practical legacy setup guidance.

Read More

Sonar PDF Report Plugin 2.1: Integrations, SVG Support, and What the Release Actually Added

This revised note explains what was explicitly announced for Sonar PDF Report Plugin 2.1: broader plugin data inclusion and SVG image support. It also maps the reporting workflow and gives a practical adoption checklist for DevOps teams maintaining legacy Sonar setups.

Read More

Sonar 2.2 Release Highlights: Filters, Plugin Classloaders, and Upgrade Notes

Sonar 2.2 introduced homepage filters and independent plugin classloaders, aimed at faster quality triage and easier plugin development. This revised guide explains what changed, why it mattered, and where to find the original release resources.

Read More
Subscribe
Notify of
guest
1 Comment
Newest
Oldest Most Voted
Skylar Bennett
Skylar Bennett
5 months ago

One aspect worth expanding on is treating sonar-project.properties as 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. 

1
0
Would love your thoughts, please comment.x
()
x