SonarScanner
$ sonar-scanner Official Med RiskOfficial SonarSource scanner CLI that bundles project metadata, runs language analyzers locally, and uploads analysis reports to a SonarQube Server or SonarCloud instance. Designed for CI pipelines rather than headless agent local loops: emits verbose JVM logs without stdout JSON findings and requires SONAR_TOKEN plus a live server.
brew install sonar-scanner sonar-scanner uploads analysis snapshots to SonarQube/SonarCloud, whereas querying issues and quality-gate status afterward is cleaner via SonarQube REST API or MCP.
Agent-Readiness Checklist
Static evaluation (not yet probed on this host). Run npm run data:probe locally to capture live verification.
FCRS-1.0 6-Dimension Breakdown
Emits noisy multi-line INFO logs and uploads results asynchronously to a server rather than returning --json findings to stdout.
- No
--jsonstdout report for code findings - Requires polling the SonarQube Web API for Quality Gate results unless
-Dsonar.qualitygate.wait=trueis configured
Uploads source analysis payloads to a remote server using SONAR_TOKEN and leaves .scannerwork/ caches locally.
- Remote upload side effect on every scan run
- Supports
SONAR_TOKENenv var isolation
Heavy distribution with JVM/JRE dependency plus mandatory reachable SonarQube or SonarCloud backend.
- Cannot produce standalone offline lint results without a Sonar server
Valuable for organizations standardized on SonarQube Quality Gates, but overkill compared to ruff, eslint, or semgrep in agent edit loops.
- Heavy CI-oriented batch workflow
Official SonarSource CLI (SonarSource/sonar-scanner-cli) under LGPL-3.0.
- Official
SonarSource/sonar-scanner-clirepository
Extensive official docs across SonarQube Server and SonarCloud, though -Dsonar.* properties vary by language plugin.
- Official docs at docs.sonarsource.com
Security, Auth & Guardrails
Authenticates via SONAR_TOKEN env var (preferred) or sonar.token in sonar-project.properties.
Scanner CLI is LGPL-3.0 free; SonarQube Community is free while Enterprise/SonarCloud plans are commercial.
# SonarScanner Agent Rules - Never run `sonar-scanner` blindly as a local linter; it uploads reports to a remote SonarQube/SonarCloud server and writes `.scannerwork/`. - Supply `SONAR_TOKEN` via environment variable rather than hardcoding tokens in `sonar-project.properties`.
Agent-Ready Command Recipes
Safe Read-Only Queries
sonar-scanner --version
Prints the installed scanner and embedded JRE versions without uploading any scan.
Controlled Writes & Previews
sonar-scanner -Dsonar.projectKey=my-app -Dsonar.host.url=https://sonar.example.com
Analyzes local sources and uploads the report to SonarQube using SONAR_TOKEN; writes .scannerwork/ locally.
Strengths for Agents
- + Official launcher supporting SonarQube and SonarCloud Quality Gates across 30+ languages.
- + Honors
SONAR_TOKENenvironment variable for clean CI/CD authentication.
Caveats & Pitfalls
- ! Cannot run as an offline local linter; every scan requires a SonarQube/SonarCloud server and uploads project data.
- ! Outputs verbose JVM logs with no local JSON findings format; agents must query the server API for issues.