Prevent sonar scanner to fail during a "rebuild" on Jenkins (no code compiled)


is it possible to run sonar-scanner after an incremental rebuild (using build-wrapper), in a way that it won’t fail if it finds “0 compilation units”?

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)

    • SonarQube 8.2 Developer Edition
    • SonarCfamily 6.8.0
    • SonarScanner
    • Jenkins SonarQube Scanner 2.11
  • what are you trying to achieve

We have a Jenkins job building each master branch commit of a Git repository.
Build is:

  • incremental compilation of code (with build-wrapper)
  • sonar analysis using Jenkins Sonar scanner plugin
  • tests on hardware (take some time)

Sometime, hardware can fail and so we manually relaunch the Jenkins job.
But in that case, as code is the same, incremental compilation won’t do anything. So build-wrapper won’t capture build outputs. And sonar-scanner fails with error:

INFO: 0 compilation units analyzed
INFO: ------------------------------------------------------------------------
INFO: ------------------------------------------------------------------------
INFO: Total time: 24.320s
INFO: Final Memory: 29M/981M
INFO: ------------------------------------------------------------------------
ERROR: Error during SonarScanner execution
java.lang.IllegalStateException: The “build-wrapper-dump.json” file was found but 0 C/C++/Objective-C files were analyzed. Please make sure that:

  • you are using the latest version of the build-wrapper and the SonarCFamily analyzer
  • you are correctly invoking the scanner with correct configuration
  • your compiler is supported
  • you are wrapping your build correctly
  • you are wrapping a full/clean build
  • you are providing the path to the correct build-wrapper output directory
  • you are building and analyzing the same source checkout, absolute paths must be identical in build and analysis steps
    at com.sonar.cpp.plugin.CFamilySensor.execute(
    at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(
    at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(
    at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(
    at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(
    at org.sonar.core.platform.ComponentContainer.startComponents(
    at org.sonar.core.platform.ComponentContainer.execute(
    at org.sonar.scanner.scan.ProjectScanContainer.scan(
    at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(
    at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(
    at org.sonar.core.platform.ComponentContainer.startComponents(
    at org.sonar.core.platform.ComponentContainer.execute(
    at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(
    at org.sonar.core.platform.ComponentContainer.startComponents(
    at org.sonar.core.platform.ComponentContainer.execute(
    at org.sonar.batch.bootstrapper.Batch.doExecute(
    at org.sonar.batch.bootstrapper.Batch.execute(
    at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(
    at java.lang.reflect.Method.invoke(
    at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(
    at com.sun.proxy.$Proxy0.execute(Unknown Source)
    at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(
    at org.sonarsource.scanner.api.EmbeddedScanner.execute(
    at org.sonarsource.scanner.cli.Main.execute(
    at org.sonarsource.scanner.cli.Main.execute(
    at org.sonarsource.scanner.cli.Main.main(

Hello @scm_invn.

Thanks for reaching out to us.
We do not support incremental compilation out-of-the box.
If it is important for you to have something equivalent, here is what I can suggest.

In such a way, if a build fails for hardware reasons, all the compiled files are cached by ccache. On the next clean build, all the compilation commands are run by the build system and intercepted by the build-wrapper, so it will not be empty. At the same time, the compilation is not run again since it is cached (hence the speed up). Finally, the analysis cache allows that only file newly modified files are analyzed.