sonar-scanning-examples: a map of which SonarScanner to reach for per build system
Shows how to use the Scanners
At a glance
- What is it?
- SonarSource's sonar-scanning-examples repository is a catalogue of small, runnable scanner setups for Ant, Gradle, Maven, .NET, Swift and miscellaneous languages. It is documentation by example, and its most useful content is the recommendation table: which scanner variant fits which build tool.
- Who is it for?
- Use sonar-scanning-examples when you are standing up SonarQube analysis for the first time in a repository and want a working reference for your exact build tool rather than a generic guide, or when you are migrating a deprecated Ant setup to the CLI. Do not use it as a source of configuration truth for production pipelines, because each example is deliberately minimal and the repository states that it contains practical examples, not supported configurations.
- Can I use it commercially?
- Yes, with conditions. LGPL-3.0 is a weak copyleft licence: you can use it inside commercial and closed-source software, but if you distribute changes to its own files, you must publish those changes under the same licence.
- Is it still maintained?
- Yes. The repository last received commits 17 days ago.
- What is it written in?
- Mainly Bicep, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on October 23, 2026, and from our analysis. They are not legal advice.
Editorial analysis
The repository is a directory of small scanner projects, not a library
sonar-scanning-examples is described as a repository containing practical examples for running SonarScanners and importing code coverage across multiple languages and build systems. The structure makes that concrete. Each top level folder is a scanner family, and inside each one sit individual example projects: sonar-scanner-ant holds ant-basic and ant-coverage, sonar-scanner-gradle holds gradle-basic, gradle-kotlin-dsl, gradle-kotlin-project, gradle-multimodule and gradle-multimodule-coverage, sonar-scanner-maven holds maven-basic, maven-multilingual, maven-multimodule and a shared sonar-scanner folder for miscellaneous languages. The README tells you how to use it in one line: pick an example for your language and build system, then follow that project's own instructions. So the unit of value is the individual example project, not the repository. If you want the reasoning behind a scanner choice, this is the wrong place. If you want a configuration that has been made to work in a specific build tool, this is exactly the right place.
The recommendation table is the part worth keeping
The README is effectively a mapping from build system to scanner, and it is explicit about which one to pick. For Gradle, the recommendation is SonarScanner for Gradle or the equivalent gradle sonar task in the CI pipeline. For Maven, it is SonarScanner for Maven or the equivalent sonar-maven-plugin goal. For .NET, it is SonarScanner for .NET, listed as the equivalent on a CI pipeline. The Ant case is the interesting one, because it is the only entry where the answer is not a dedicated scanner. The README notes that scanning an Ant project is no different than scanning a plain Java project with no build tool: Ant is used to build the project but not to run the scan, and the SonarScanner CLI is used instead. The SonarScanner for Ant is marked as deprecated, with a pointer to the Ant documentation page and an instruction to migrate to the CLI. That deprecation is the concrete maintenance signal in the repository, and it is a useful one for anyone maintaining older Java build estates.
In a Gradle build, the task the README points at is the one the Gradle plugin registers:
gradle sonarIn a Maven build it is the plugin goal:
mvn org.sonarsource.scanner.maven:sonar-maven-plugin:sonarBoth are the CI-facing form of the dedicated scanner for that build tool, which is why the README treats them as equivalent rather than as a separate option.
Code coverage is a first class example, not an afterthought
Roughly a third of the example folders have coverage as their explicit subject. Ant has ant-coverage alongside ant-basic, Gradle has gradle-multimodule-coverage, Maven has maven-multilingual, described as Java plus Kotlin with coverage, and there is a top level swift-coverage folder for Swift. Multi-module setups get their own treatment too, since aggregating coverage across modules is where a naive configuration usually breaks. The practical implication is that the coverage path is exercised in more than one language family, which makes the examples usable as a pattern rather than a single anecdote. The top level sonar-scanner folder is described as covering all the languages available, with the instruction that you can scan everything or change directory into a language folder to scan just that one. That directory-switching trick is worth knowing about, because a monorepo with several languages in one checkout is a common case and the alternative is one analysis per language.
The scanner documentation links are the real reference, the examples are the practice
The README separates examples from documentation deliberately. At the top it points to the SonarQube product page to learn more about the products used with the examples, and then lists dedicated documentation pages for SonarScanner for Gradle, for .NET and for Maven, plus the SonarScanner CLI page and the deprecated Ant page. Every example is also linked to its scanner's documentation. That structure tells you how to read the repository: the example gives you the working shape, the documentation link gives you the authoritative behaviour and options. One section breaks the pattern. The C, C++ and Objective-C examples are not in this repository at all, but in a separate one, sonarsource-cfamily-examples, which is described as holding SonarSource sample C and C++ projects with SonarQube Cloud or SonarQube Server analysis configured, across different CI pipelines and build systems for Linux, Windows and Mac. So a C or C++ user gets pointed away from here entirely.
No releases, a maintained master branch, and a marketing process baked in
The repository publishes no GitHub releases at all. What it has is a steady commit stream: the last push was on 2026-10-06 and the project is not archived, so examples are still being updated to match current scanner behaviour. That is the right shape for this kind of repository, since a released archive of examples would immediately start drifting from the scanners they demonstrate. The tree also shows the internal structure plainly, with one directory per scanner family plus .github, SECURITY.md, LICENSE.txt and NOTICE.txt. There is a human process visible in the README too, in the form of a comment saying the marketing section is maintained by SonarSource and that wording changes need the relevant Product Marketing Manager, while CODEOWNERS review accuracy and merge changes. That split between who edits the words and who reviews the technical content tells you something about how the project is run, and it is also a warning to readers that the README is partly a marketing surface.
LGPL-3.0 covers the examples, and the projects inside them carry their own terms
The licence field for the repository is LGPL-3.0, and the README states it plainly: Copyright 2016 to 2026 SonarSource, licensed under the GNU Lesser General Public License Version 3.0, with a LICENSE.txt and a NOTICE.txt at the root. The LGPL is a weak copyleft licence, which means the examples can be copied and modified with obligations that apply to the licensed work itself. Two practical notes for anyone reusing an example. First, the example projects wrap sample application code from other projects, and those upstream projects carry their own licences, so the licence of the configuration is not the only thing that travels with the folder. Second, this is not legal advice, and the NOTICE.txt file is the place to check what attribution the repository expects. Nothing in the README restricts use of the scanner configurations themselves, which are part of running the SonarQube products rather than part of the example code.
Where the practical limits sit for a team copying an example
The obvious limit is that an example is a demonstration, not a supported configuration. It is built to be small enough to read in one sitting and to prove that a particular scanner invocation works against a particular build tool. It will not contain your monorepo's module layout, your authentication setup, your quality gate thresholds, or your split of analysis across several SonarQube projects. The second limit is the version coupling: the README points at SonarQube Server documentation paths, including one versioned path in the Ant section, and scanners change their options between releases, so an example copied a year ago can carry a property that no longer does anything or that has been renamed. The third limit is that these are client-side scans and the repository says nothing about the server side of a SonarQube deployment, so it will not tell you anything about sizing, plugin choice or scanner selection policy. Treat what is here as a working reference to adapt, and the linked scanner documentation as the authority.
Editorial conclusion
Use sonar-scanning-examples when you are standing up SonarQube analysis for the first time in a repository and want a working reference for your exact build tool rather than a generic guide, or when you are migrating a deprecated Ant setup to the CLI. Do not use it as a source of configuration truth for production pipelines, because each example is deliberately minimal and the repository states that it contains practical examples, not supported configurations. Before adopting anything from it, read the example that matches your build tool end to end, check the scanner documentation links for the current version, and confirm whether your SonarQube instance is Community or Server, since the project points at both SonarQube Cloud and SonarQube Server paths for the C and C++ examples it links out to.
Frequently asked questions
Which SonarScanner should I use for a Gradle project?
The README recommends SonarScanner for Gradle, or the equivalent gradle sonar task in your CI pipeline. The repository includes basic, Kotlin DSL, Kotlin, multi-module and multi-module coverage examples under sonar-scanner-gradle.
Is SonarScanner for Ant deprecated?
Yes. The README states that SonarScanner for Ant is deprecated and asks you to migrate to the SonarScanner CLI, noting that scanning an Ant project is no different from scanning a plain Java project with no build tool.
Where are the C and C++ examples in sonar-scanning-examples?
They are not in this repository. The README points to a separate repository, sonarsource-cfamily-examples, which holds SonarSource sample C and C++ projects configured for SonarQube Cloud or SonarQube Server across Linux, Windows and Mac.
How do I import code coverage with these examples?
Several example folders are built around coverage, including ant-coverage, gradle-multimodule-coverage and a swift-coverage folder, plus a Maven multilingual example described as Java plus Kotlin with coverage. Each one carries its own instructions in its folder.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/sonarsource-sonar-scanning-examples)Was this useful?