Scanner Ecosystem: CLI, Maven, Gradle, .NET, and Build Integration: Diagnostics, Failure Modes, and Production Practices
Diagnose scanner failures by locating the broken build/lifecycle/runtime/indexing layer before touching server policy, credentials, or infrastructure.
Learning objectives
- Distinguish build failure, scanner failure, report upload, Compute Engine failure, and gate failure.
- Diagnose a deliberately missing Java bytecode condition without hiding it with exclusions.
- Explain why .NET begin/build/end ordering and working-directory semantics matter.
- Preserve scanner cache/log/task evidence before cleanup or retries.
- Apply the least destructive correction and rerun the smallest equivalent scenario.
1. Evidence-first diagnostic sequence
- Preserve the exact build/scanner command, stdout/stderr, environment manifest, and source revision.
- Record server, scanner/plugin, build tool, Java/.NET runtime, and relevant plugin versions.
- Confirm project/base directory and effective analysis parameters.
- Inspect whether compilation/test/coverage outputs exist before scan.
-
Inspect scanner indexing/report creation and
report-task.txt. - If uploaded, follow the exact Compute Engine task.
- Only after CE success interpret project issues/measures/gate.
- Change one cause and rerun the smallest equivalent path.
2. Failure ownership matrix
| Symptom | Likely layer | Preserve first | Do not jump to |
|---|---|---|---|
mvn verify fails |
build/test/dependency | Maven log + revision | SonarQube gate |
| Java analyzer says bytecode missing | build/scanner input | class directory + scanner log | mass exclusions |
| .NET end cannot complete | begin/build/end lifecycle | all three commands/logs | server restart |
| wrong files indexed | base dir/parameters/build model | working dir + effective config | new project key |
| report uploaded, CE FAILED | server Compute Engine | task ID/server task log | rerun with admin token |
| CE SUCCESS, gate ERROR | project policy/result | gate conditions + measures | scanner reinstall |
3. Intentionally broken example: remove Java bytecode
In the Maven fixture from Lesson 2, first preserve the known-good build tree. Then deliberately remove compiled classes before invoking analysis in a way that expects Java bytecode.
cd sonar-p07-maven
mvn -B clean verify
find target/classes -type f -print | sort > classes.before.txt
rm -rf target/classes
# Deliberately broken: analysis now lacks the compiled Java context.
mvn -B org.sonarsource.scanner.maven:sonar-maven-plugin:5.7.0.6970:sonar -Dsonar.host.url="$SONAR_HOST_URL" | tee broken-bytecode.log
Expected diagnostic lesson: the failure/warning belongs to
build input, not to the Quality Gate. Preserve
broken-bytecode.log, confirm the missing directory,
then restore by rebuilding—do not suppress Java files or fabricate
an unrelated binaries path.
mvn -B clean verify
mvn -B org.sonarsource.scanner.maven:sonar-maven-plugin:5.7.0.6970:sonar -Dsonar.host.url="$SONAR_HOST_URL" | tee repaired-bytecode.log
4. .NET lifecycle failure: build outside the envelope
A common conceptual error is to run dotnet build, then
later call only the scanner end step or start a new begin/end around
no build. The .NET scanner analysis context is not retroactively
reconstructed from arbitrary output folders. Preserve the commands
and timestamps, then repair by rerunning begin → build → end as one
controlled sequence.
5. Wrong working/base directory
Scanner CLI, Maven, Gradle, and .NET do not all infer project base
directories identically. Before changing paths, record
pwd, repository root, build descriptor locations,
sonar.projectBaseDir if set, and indexed-file logs. The
.NET scanner changed automatic project-base detection in modern
versions, making legacy assumptions particularly dangerous.
6. Scanner/plugin version drift
A pipeline that invokes an unversioned Maven prefix or downloads “latest” CLI can change independently of the server. When a regression appears, preserve the resolved scanner version before retrying. Compare against the server compatibility matrix and the scanner release notes. Roll back only to a supported, previously validated version—not to an arbitrary ancient scanner.
7. Cache problems without evidence destruction
Permissions or corrupted downloads under the scanner user home can
fail provisioning. Record SONAR_USER_HOME, ownership,
free space, and the failing artifact path. Avoid deleting the entire
cache before preserving the failure. A targeted disposable-cache
test can isolate cache ownership from project analysis without
destroying the original evidence.
8. Security-sensitive troubleshooting boundaries
- Do not switch to an administrator token to bypass permission diagnosis.
-
Do not print all environment variables to discover
SONAR_TOKEN. - Do not disable TLS verification as a generic proxy fix.
- Do not delete server database/search state because a local scanner cannot find bytecode.
- Do not lower Quality Gate thresholds to convert a policy result into a scanner “success.”
9. Smallest-equivalent rerun principle
If the failure was missing Maven bytecode, keep the same revision, project key, token scope, server, scanner version, and gate. Rebuild classes and rerun. If the failure was a wrong base directory, change only that path. This causal discipline is what makes the repaired run comparable to the failed run.
Knowledge check
A Java scan lacks bytecode. Should you lower the Quality Gate?
No. The failure is an analysis-input/build-context problem, not a policy-threshold problem.
What should you preserve before clearing a scanner cache?
The failing path, cache location/ownership, logs, scanner/runtime versions, and first-failure evidence.
Why can a .NET build completed before begin be
insufficient?
The scanner captures analysis context through the begin/build/end lifecycle; an earlier unrelated build is outside that envelope.
A scanner upgrade breaks CI. What is the first version question?
Which scanner/plugin version actually resolved in the failing run and whether it is supported with the server/build runtime.
What is the safest diagnostic rerun?
The same revision and inputs with only the identified cause changed.
Official references and version notes
- SonarScanner CLI — build-neutral scanner usage, cache behavior, project base directory, and Docker notes.
- SonarScanner CLI 8.1.0.6389 — official release provenance.
- SonarScanner for Maven and release 5.7.0.6970.
- SonarScanner for Gradle and release 7.3.1.8318.
- SonarScanner for .NET usage and release 11.2.1.137242.
- Scanner environment general requirements and JRE auto-provisioning.
- Official scanner examples — recommended scanner choice by build ecosystem.
- Apache Maven downloads — Maven 3.9.16 is the current stable Maven baseline used in the Maven lab.
Rechecked on 2026-09-07. The chapter targets local/private Community Build 26.9.0.129388. Current release baselines used for reproducible examples are Scanner CLI 8.1.0.6389, SonarScanner for Maven 5.7.0.6970, SonarScanner for Gradle 7.3.1.8318, and SonarScanner for .NET 11.2.1.137242. Mandatory execution uses CLI plus Maven; Gradle and .NET are optional executable extensions when their build prerequisites are installed. JRE auto-provisioning is kept enabled unless a lesson explicitly demonstrates the system-Java boundary. Re-check current scanner/server compatibility before future runs because scanner release trains move independently.
Keep the academy open
Support free, practical DevOps education.
Every lesson is designed to remain readable in a browser, downloadable from GitHub, and usable without a paid learning platform. Contributions help expand and maintain the curriculum.
0x716c4Ab160C4B66F31a28AE2448BfF68fc3a2ef0Send only Ethereum/ERC-20 compatible assets to this
address.