I just started evaluating SonarQue (both Community or Developer edition). Really appreciated it if someone could help me with the error that I got below when I ran the sonarqueb-scanner CLI on Mac OS (Apple M1 Max, Sonoma 14.5).
I had the sonar database and sonar server running from Docker containers. They were up & running successfully. However, when I ran the sonar-scanner CLI below from one of my git repo projects, I always got the “Failed to get server version” or 400 error returned as shown below. I was able to access to http://localhost:9001/api/v2/analysis/version fine with expected result (“24.12.0.100206”). Same for http://localhost:9001/api/server/version. I got the the error regardless if I used the Community edition or Developer edition. Here’s is the console log:
"sonar-scanner \
-Dsonar.projectKey=ph_eval \
-Dsonar.sources=. \
-Dsonar.host.url=http://localhost:9001 \
-Dsonar.token=<token>
16:02:55.050 INFO Scanner configuration file: /opt/homebrew/Cellar/sonar-scanner/6.2.1.4610/libexec/conf/sonar-scanner.properties
16:02:55.053 INFO Project root configuration file: NONE
16:02:55.063 INFO SonarScanner CLI 6.2.1.4610
16:02:55.064 INFO Java 23.0.1 Homebrew (64-bit)
16:02:55.067 INFO Mac OS X 14.5 aarch64
16:02:55.191 INFO User cache: /Users/phoang/.sonar/cache
16:02:55.672 INFO EXECUTION FAILURE
16:02:55.672 INFO Total time: 0.625s
16:02:55.672 ERROR Error during SonarScanner CLI execution
java.lang.IllegalStateException: Failed to get server version
at org.sonarsource.scanner.lib.ScannerEngineBootstrapper.getServerVersion(ScannerEngineBootstrapper.java:194)
at org.sonarsource.scanner.lib.ScannerEngineBootstrapper.bootstrap(ScannerEngineBootstrapper.java:117)
at org.sonarsource.scanner.cli.Main.analyze(Main.java:75)
at org.sonarsource.scanner.cli.Main.main(Main.java:63)
Suppressed: java.lang.IllegalStateException: Error status returned by url [http://localhost:9001/api/v2/analysis/version]: 400
at org.sonarsource.scanner.lib.internal.http.ScannerHttpClient.callUrl(ScannerHttpClient.java:163)
at org.sonarsource.scanner.lib.internal.http.ScannerHttpClient.callApi(ScannerHttpClient.java:126)
at org.sonarsource.scanner.lib.internal.http.ScannerHttpClient.callRestApi(ScannerHttpClient.java:104)
at org.sonarsource.scanner.lib.ScannerEngineBootstrapper.getServerVersion(ScannerEngineBootstrapper.java:189)
... 3 common frames omitted
Caused by: java.lang.IllegalStateException: Error status returned by url [http://localhost:9001/api/server/version]: 400
at org.sonarsource.scanner.lib.internal.http.ScannerHttpClient.callUrl(ScannerHttpClient.java:163)
at org.sonarsource.scanner.lib.internal.http.ScannerHttpClient.callApi(ScannerHttpClient.java:126)
at org.sonarsource.scanner.lib.internal.http.ScannerHttpClient.callWebApi(ScannerHttpClient.java:112)
at org.sonarsource.scanner.lib.ScannerEngineBootstrapper.getServerVersion(ScannerEngineBootstrapper.java:192)
... 3 common frames omitted
16:02:55.673 ERROR
16:02:55.673 ERROR Re-run SonarScanner CLI using the -X switch to enable full debug logging.
(base) phoang@Phuongs-MacBook-Pro-2 c2patool-automation % sonar-scanner \
-Dsonar.projectKey=ph_eval \
-Dsonar.sources=. \
-Dsonar.host.url=http://localhost:9001 \
-Dsonar.token=sqp_1cfa740d182f63fb2501247b4e05c50bba35aac7 -X
16:03:50.435 INFO Scanner configuration file: /opt/homebrew/Cellar/sonar-scanner/6.2.1.4610/libexec/conf/sonar-scanner.properties
16:03:50.439 INFO Project root configuration file: NONE
16:03:50.449 INFO SonarScanner CLI 6.2.1.4610
16:03:50.451 INFO Java 23.0.1 Homebrew (64-bit)
16:03:50.453 INFO Mac OS X 14.5 aarch64
16:03:50.459 DEBUG Scanner max available memory: 8 GB
16:03:50.494 DEBUG uname -m returned 'arm64'
16:03:50.496 DEBUG Create: /Users/phoang/.sonar/cache
16:03:50.496 INFO User cache: /Users/phoang/.sonar/cache
16:03:50.496 DEBUG Create: /Users/phoang/.sonar/cache/_tmp
16:03:50.660 DEBUG Successfully loaded KeyStore of the type [KeychainStore] having [13] entries
16:03:50.800 DEBUG Loaded [181] system trusted certificates
16:03:50.993 DEBUG --> GET http://localhost:9001/api/v2/analysis/version
16:03:51.023 DEBUG <-- 400 Bad Request http://localhost:9001/api/v2/analysis/version (29ms, unknown-length body)
16:03:51.024 DEBUG --> GET http://localhost:9001/api/server/version
16:03:51.048 DEBUG <-- 400 Bad Request http://localhost:9001/api/server/version (23ms, unknown-length body)
16:03:51.048 INFO EXECUTION FAILURE
16:03:51.048 INFO Total time: 0.616s
16:03:51.048 ERROR Error during SonarScanner CLI execution
java.lang.IllegalStateException: Failed to get server version
at org.sonarsource.scanner.lib.ScannerEngineBootstrapper.getServerVersion(ScannerEngineBootstrapper.java:194)
at org.sonarsource.scanner.lib.ScannerEngineBootstrapper.bootstrap(ScannerEngineBootstrapper.java:117)
at org.sonarsource.scanner.cli.Main.analyze(Main.java:75)
at org.sonarsource.scanner.cli.Main.main(Main.java:63)
Suppressed: java.lang.IllegalStateException: Error status returned by url [http://localhost:9001/api/v2/analysis/version]: 400
at org.sonarsource.scanner.lib.internal.http.ScannerHttpClient.callUrl(ScannerHttpClient.java:163)
at org.sonarsource.scanner.lib.internal.http.ScannerHttpClient.callApi(ScannerHttpClient.java:126)
at org.sonarsource.scanner.lib.internal.http.ScannerHttpClient.callRestApi(ScannerHttpClient.java:104)
at org.sonarsource.scanner.lib.ScannerEngineBootstrapper.getServerVersion(ScannerEngineBootstrapper.java:189)
... 3 common frames omitted
Caused by: java.lang.IllegalStateException: Error status returned by url [http://localhost:9001/api/server/version]: 400
at org.sonarsource.scanner.lib.internal.http.ScannerHttpClient.callUrl(ScannerHttpClient.java:163)
at org.sonarsource.scanner.lib.internal.http.ScannerHttpClient.callApi(ScannerHttpClient.java:126)
at org.sonarsource.scanner.lib.internal.http.ScannerHttpClient.callWebApi(ScannerHttpClient.java:112)
at org.sonarsource.scanner.lib.ScannerEngineBootstrapper.getServerVersion(ScannerEngineBootstrapper.java:192)
... 3 common frames omitted
"