Sonar Scanner analysis Issue

I have two files named swap.c and fac.c, both placed at under same directory.
I need to run analysis for fac.c only. However, when i run scanner at base dir with below project properties, both the files are indexed and displayed in UI which is undesireable.

I want ONLY compiled/built code to be considered for analysis

[build wrapper]
build-wrapper-linux-x86-64 --out-dir bw-output gcc fac.c

[Tool details]

  • Sonarqube -9.0
  • sonar-scanner-cli-
  • PostgreSQL 12.9


I have attached sonar-scanner -X logs

log.txt (71.3 KB)

Please let me know if my understanding wrong

Hey there.

Sounds like you want to Narrow the Focus.

Hello Colin,

If i have to “Narrow the focus” to avoid unnecessary code to be analyzed, then what role is build wrapper playing ?
I am under assumption that analysis is directly based on what gets recorded in build wrapper step. In this case only fac.c compilation was recorded in build-wrapper-dump.json
build-wrapper.log (15.2 KB)
build-wrapper-dump.json (2.0 KB)

Whereas analysis considers both the files

@Colin / @ganncamp can you comment on the query ?

Hey there.

The build-wrapper collects necessary information to perform analysis – however, other files captured by sonar.sources will still be indexed.