SonarQube and Code Quality Tutorial
Learn SonarQube and Code Quality step by step: 37 lessons in 9 chapters with examples, quizzes, diagrams and projects.
Start learning →
of lessons completed
Getting Started
- What Is SonarQube? Learn what SonarQube does, what problems it finds in source code, and where it fits in a team workflow, with a runnable mini analyzer that shows the idea.
- Static Analysis Explained Understand how static analysis finds bugs without running code: parsing, syntax trees, control flow and data flow, and why it differs from testing and from regex search.
- Bugs, Vulnerabilities and Code Smells Learn the issue types SonarQube reports, how severity and ratings work, and how a project gets its A to E reliability, security and maintainability grades.
- Editions and Hosting Options Compare SonarQube Community Build, Developer, Enterprise and Data Center editions with SonarQube Cloud, and learn how lines of code are counted for licensing.
- Your First Analysis Walk through a first SonarQube scan: create a project, generate a token, add sonar-project.properties, run the scanner and read the result. Includes a properties validator.
Concepts and Setup
- SonarQube Architecture and Components Understand the parts of a SonarQube server (web server, compute engine, search engine, database) and what happens to an analysis report from upload to dashboard.
- Installing SonarQube with Docker Run SonarQube locally with Docker and Docker Compose: system limits, a PostgreSQL database, volumes, first login, and a generator and checker for the config.
- Projects, Branches and Pull Requests Learn how SonarQube organizes code into projects, project keys, branches and pull requests, how analyses compare to each other, and how to name things well.
- Users, Tokens and Permissions Learn how SonarQube handles users and groups, the three token types, global and project permissions, and how to give CI the least privilege it needs to scan.
- The Issue Lifecycle Follow a SonarQube issue from creation to closure: statuses, resolutions, false positives and accepted issues, assignment, comments, tracking across scans and bulk changes.
Rules and Quality Gates
- Rules and Quality Profiles Learn how SonarQube rules are keyed and described, how quality profiles choose which rules run per language, how inheritance and copies work, and how to tune a profile.
- The Clean Code Taxonomy Learn the Clean Code taxonomy: software qualities (security, reliability, maintainability), clean code attributes, impact severities, and how legacy issue types map to it.
- Quality Gates Understand quality gate conditions on new and overall code, the Sonar way default gate, how to build a custom gate, and how pipelines read the pass or fail result.
- New Code and Clean as You Code Learn the Clean as You Code approach and the new code definition options: previous version, number of days, reference branch and specific analysis, with calculators.
- Complexity and Duplication Learn how SonarQube measures cyclomatic and cognitive complexity and finds duplicated blocks, with runnable Python calculators that mimic both metrics.
Scanning and Integrations
- The Scanner Command Line Learn the SonarScanner command line: installation, the core analysis properties, property precedence, environment variables, multi-module projects and verbose debugging.
- Scanners for Build Tools Run SonarQube analysis through Maven, Gradle, .NET and Node.js: the commands, the key properties, why compiled languages need build output, and a command generator.
- Exclusions and Test Sources Control what SonarQube analyzes: sonar.exclusions, inclusions, test sources, coverage and duplication exclusions, ant-style patterns, and an interactive pattern matcher.
- Pull Request Analysis and IDEs Bring SonarQube feedback to reviewers and developers: DevOps platform integrations, pull request decoration and status checks, and SonarQube for IDE in connected mode.
Security Hotspots
- Security Hotspots vs Vulnerabilities in SonarQube Learn how SonarQube separates vulnerabilities from security hotspots, why hotspots need a human review, and how each one affects the security rating and the quality gate.
- Reviewing Security Hotspots: A Step-by-Step Workflow A practical workflow for reviewing SonarQube security hotspots: open the risk description, decide Safe, Fixed or Acknowledged, comment, assign, and handle permissions and priorities.
- OWASP Top 10, CWE and SonarQube Security Reports See how SonarQube rules map to OWASP Top 10 categories and CWE weaknesses, how to read the security reports, and how to group findings by category with a runnable stand-in.
Coverage and Technical Debt
- Code Coverage in SonarQube: Line and Condition Coverage Understand how SonarQube measures coverage, the difference between line and condition coverage, coverage on new code, and exclusions, with a calculator you can run.
- Importing Coverage Reports: JaCoCo, LCOV, Cobertura and More Configure SonarQube to import coverage from JaCoCo, LCOV, Cobertura, OpenCover and the generic format, with property names per language and a parser stand-in you can run.
- Technical Debt and the A-to-E Ratings in SonarQube Learn how SonarQube estimates technical debt, computes the debt ratio and the Maintainability, Reliability and Security ratings from A to E, with runnable calculators.
- Duplications, Cyclomatic and Cognitive Complexity in SonarQube How SonarQube finds duplicated code, how cyclomatic and cognitive complexity differ, which thresholds trigger issues, and how to try both ideas with runnable stand-ins.
CI Integration
- SonarQube in a CI Pipeline: The Big Picture Understand where SonarQube analysis fits in CI: checkout, build, test, scan, quality gate. Learn the scanner properties, secrets, and failure modes, with a pipeline simulator.
- SonarQube with GitHub Actions: Workflow Files Explained Set up SonarQube analysis in GitHub Actions: secrets, a workflow for push and pull requests, Maven, Gradle and .NET variants, the quality gate check, and a workflow linter stand-in.
- SonarQube in GitLab CI, Jenkins and Azure DevOps Pipelines Configure SonarQube analysis in GitLab CI, Jenkins (withSonarQubeEnv and waitForQualityGate) and Azure DevOps (Prepare, Analyze, Publish), with the settings each one needs.
- Pull Request Analysis, Decoration and Quality Gate Wait How SonarQube analyses pull requests, which parameters identify them, how decoration reports status to GitHub or GitLab, and how to enforce the quality gate before merging.
Administration
- SonarQube Users, Groups and Permissions Manage SonarQube access: global and project permissions, groups, permission templates, project visibility, and the safe defaults to set on a new server, with a permission checker.
- SonarQube Authentication: LDAP, SAML, GitHub Login and Tokens Configure SonarQube sign-in with local accounts, LDAP, SAML and GitHub, understand user, project and global analysis tokens, and handle token rotation safely.
- SonarQube Database, Backups, Housekeeping and Upgrades Plan a production SonarQube: the database, sonar.properties, JVM memory, backups, housekeeping, and a safe upgrade path with the Long-Term Active release, plus a checklist stand-in.
- SonarQube Web API: Measures, Issues, Gates and Automation Use the SonarQube Web API to read quality gate status, measures, issues and hotspots, handle paging, and automate reports and badges, with response parsers you can run.
Projects and Practice
- Project: Put a Quality Gate on a Repository, Start to Finish Follow a complete project: create a SonarQube project, configure scanner properties, import coverage, run CI, tune a quality gate, and enforce it on pull requests.
- Project: A Clean as You Code Workflow for a Legacy Codebase Plan a Clean as You Code programme for a legacy codebase: triage the baseline, protect new code, pay debt in touched files, track trends, and report progress with scripts you can run.
- SonarQube Practice: Exercises and Interview Questions Test your SonarQube knowledge with worked calculation exercises, scenario questions, troubleshooting drills and common interview questions on hotspots, coverage, CI and administration.