sonar-project.properties Builder

Generate a SonarQube project properties file for code quality scanning

Build a sonar-project.properties file with project key, name, version, source and test directories, exclusions, server URL, source encoding, and language-specific coverage report paths for SonarQube or SonarCloud.

Where does sonar-project.properties live?

Place it in the root of the repository you scan, next to package.json. The SonarScanner CLI reads it from the working directory automatically, so no extra flags are needed for the listed keys.

SonarQube project configuration in one file

SonarQube and SonarCloud read a small properties file from the root of your repository to learn what to scan. This tool generates that sonar-project.properties from a few fields: the unique project key, source and test paths, exclusion globs, and the coverage report location for your language.

How it works

The SonarScanner CLI looks for sonar-project.properties in its working directory and parses key=value lines. The required keys are sonar.projectKey plus a server connection (sonar.host.url, and sonar.organization on SonarCloud). Analysis scope comes from sonar.sources and sonar.tests, both comma-separated directory lists, while sonar.exclusions removes matching files using Ant-style globs such as **/dist/**.

SonarQube never executes your tests. Instead it imports a coverage report your CI already generated, so the property name depends on the language. JavaScript and TypeScript use sonar.javascript.lcov.reportPaths pointing at an LCOV file; Python uses sonar.python.coverage.reportPaths; Java uses sonar.coverage.jacoco.xmlReportPaths. The builder emits the correct property for the language you select.

Tips and example

Keep the authentication token out of this file — pass it as the SONAR_TOKEN environment variable when you run the scanner. A minimal SonarCloud file looks like this:

sonar.projectKey=com.example:my-app
sonar.organization=my-org
sonar.host.url=https://sonarcloud.io
sonar.sources=src
sonar.tests=test
sonar.exclusions=**/node_modules/**,**/*.spec.ts
sonar.sourceEncoding=UTF-8
sonar.javascript.lcov.reportPaths=coverage/lcov.info

Run coverage in CI before the scan so the LCOV file exists when SonarScanner imports it.