Sonar C++ wrapper failing in parsing build-wrapper-dump.json

Hi Team,
Please help for the issue of C++ project.

I am able to generate the json file. and running build command and sonar scanner with wrapper as both running in same instance of compose. All is well till json creation but when it parses it gives below error.

10:40:41.272 DEBUG: ‘src/agent/config.cc’ generated metadata with charset ‘UTF-8’
10:40:41.286 INFO: Cache is explicitly disabled: Optional[false]
10:40:41.299 WARN:
File
/mywork/proj/wrapper_OUTPUT/build-wrapper-dump.json
was generated using 6.20.3 build-wrapper version,
which does not match analyzer 6.20.4.45706 version.

Please download matching version from the server
http://192.168.29.213:9000/static/cpp/build-wrapper-linux-x86.zip

10:40:41.347 INFO: ------------------------------------------------------------------------
10:40:41.347 INFO: EXECUTION FAILURE
10:40:41.347 INFO: ------------------------------------------------------------------------
10:40:41.347 INFO: Total time: 17.778s
10:40:41.399 INFO: Final Memory: 20M/70M
10:40:41.399 INFO: ------------------------------------------------------------------------
10:40:41.399 ERROR: Error during SonarScanner execution
java.lang.IllegalStateException: java.io.EOFException: End of input at line 155 column 16 path $.captures[7]
at com.sonar.cpp.plugin.CFamilySensor.process(CFamilySensor.java:629)
at com.sonar.cpp.plugin.CFamilySensor.process(CFamilySensor.java:373)
at com.sonar.cpp.plugin.CFamilySensor.execute(CFamilySensor.java:177)
at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:48)
at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:85)
at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:62)
at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:82)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:137)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:123)
at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:392)
at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:388)
at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:357)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:137)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:123)
at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:150)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:137)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:123)
at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:72)
at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:66)
at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
at com.sun.proxy.$Proxy0.execute(Unknown Source)
at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:189)
at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:138)
at org.sonarsource.scanner.cli.Main.execute(Main.java:112)
at org.sonarsource.scanner.cli.Main.execute(Main.java:75)
at org.sonarsource.scanner.cli.Main.main(Main.java:61)
Caused by: java.io.EOFException: End of input at line 155 column 16 path $.captures[7]
at com.google.gson.stream.JsonReader.nextNonWhitespace(JsonReader.java:1395)
at com.google.gson.stream.JsonReader.doPeek(JsonReader.java:466)
at com.google.gson.stream.JsonReader.hasNext(JsonReader.java:413)
build-wrapper-dump.json (73.4 KB)

Hello @Himanshu_Tyagi and welcome to our community!

Your build-wrapper-dump.json is incomplete so the analysis is failing. It means that the execution of your build with build-wrapper did not succeed.

Could you re-run the build-wrapper with your clean build command and make sure that the build succeeded? If it succeeds, could you share the build-wrapper.log please?

I did investigate on this again based on your comment. And I am success in doing this using sonarscanner cli. But I want it through gradle and it is failing saying.

Caused by: 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 CFamily 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

Did you disable the Gradle daemon (--no-daemon) while building with build-wrapper?

In order to help you, could you please share the build-wrapper.log as well as the build-wrapper.json?