I have started learning sonarqube and run sonar-scanner to analyse the code.
I have setup sonarqube on MAC with the help of below docker-compose file, with command docker-compose up -d
version: "3"
services:
sonarqube:
image: sonarqube:community
hostname: sonarqube
container_name: sonarqube
depends_on:
- db
environment:
SONAR_JDBC_URL: jdbc:postgresql://db:5432/sonar
SONAR_JDBC_USERNAME: sonar
SONAR_JDBC_PASSWORD: sonar
volumes:
- sonarqube_data:/opt/sonarqube/data
- sonarqube_extensions:/opt/sonarqube/extensions
- sonarqube_logs:/opt/sonarqube/logs
ports:
- "9000:9000"
db:
image: postgres:13
hostname: postgresql
container_name: postgresql
environment:
POSTGRES_USER: sonar
POSTGRES_PASSWORD: sonar
POSTGRES_DB: sonar
volumes:
- postgresql:/var/lib/postgresql
- postgresql_data:/var/lib/postgresql/data
volumes:
sonarqube_data:
sonarqube_extensions:
sonarqube_logs:
postgresql:
postgresql_data:
I have launched url http://localhost:9000 and created project manually and generated key (for simple python script in a folder), to see how it executes and analyses the report.
Executed scanner command from cli :
sonar-scanner \
-Dsonar.projectKey=<ProjectKey> \
-Dsonar.sources=. \
-Dsonar.host.url=http://localhost:9000 \
-Dsonar.token=<GeneratedToken> -X
Error :
17:32:39.993 INFO: Scanner configuration file: /Users/<username>/Downloads/sonar-scanner-5.0.1.3006-macosx/conf/sonar-scanner.properties
17:32:40.036 INFO: Project root configuration file: NONE
17:32:40.071 INFO: SonarScanner 5.0.1.3006
17:32:40.072 INFO: Java 17.0.7 Eclipse Adoptium (64-bit)
17:32:40.072 INFO: Mac OS X 13.5.2 x86_64
17:32:40.286 DEBUG: keyStore is :
17:32:40.286 DEBUG: keyStore type is : pkcs12
17:32:40.287 DEBUG: keyStore provider is :
17:32:40.287 DEBUG: init keystore
17:32:40.287 DEBUG: init keymanager of type SunX509
17:32:40.473 DEBUG: Create: /Users/<username>/.sonar/cache
17:32:40.474 INFO: User cache: /Users/<username>/.sonar/cache
17:32:40.474 DEBUG: Create: /Users/<username>/.sonar/cache/_tmp
17:32:40.478 DEBUG: Extract sonar-scanner-api-batch in temp...
17:32:40.486 DEBUG: Get bootstrap index...
17:32:40.486 DEBUG: Download: http://localhost:9000/batch/index
17:37:40.613 INFO: ------------------------------------------------------------------------
17:37:40.618 INFO: EXECUTION FAILURE
17:37:40.618 INFO: ------------------------------------------------------------------------
17:37:40.625 INFO: Total time: 5:00.668s
17:37:40.692 INFO: Final Memory: 5M/54M
17:37:40.692 INFO: ------------------------------------------------------------------------
17:37:40.693 ERROR: Error during SonarScanner execution
org.sonarsource.scanner.api.internal.ScannerException: Unable to execute SonarScanner analysis
at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.lambda$createLauncher$0(IsolatedLauncherFactory.java:85)
at java.base/java.security.AccessController.doPrivileged(Unknown Source)
at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.createLauncher(IsolatedLauncherFactory.java:74)
at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.createLauncher(IsolatedLauncherFactory.java:70)
at org.sonarsource.scanner.api.EmbeddedScanner.doStart(EmbeddedScanner.java:185)
at org.sonarsource.scanner.api.EmbeddedScanner.start(EmbeddedScanner.java:123)
at org.sonarsource.scanner.cli.Main.execute(Main.java:74)
at org.sonarsource.scanner.cli.Main.main(Main.java:62)
Caused by: java.lang.IllegalStateException: Fail to get bootstrap index from server
at org.sonarsource.scanner.api.internal.BootstrapIndexDownloader.getIndex(BootstrapIndexDownloader.java:42)
at org.sonarsource.scanner.api.internal.JarDownloader.getScannerEngineFiles(JarDownloader.java:58)
at org.sonarsource.scanner.api.internal.JarDownloader.download(JarDownloader.java:53)
at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.lambda$createLauncher$0(IsolatedLauncherFactory.java:76)
... 7 more
Caused by: java.net.SocketTimeoutException: timeout
at org.sonarsource.scanner.api.internal.shaded.okio.Okio$4.newTimeoutException(Okio.java:232)
at org.sonarsource.scanner.api.internal.shaded.okio.AsyncTimeout.exit(AsyncTimeout.java:286)
at org.sonarsource.scanner.api.internal.shaded.okio.AsyncTimeout$2.read(AsyncTimeout.java:241)
at org.sonarsource.scanner.api.internal.shaded.okio.RealBufferedSource.read(RealBufferedSource.java:51)
at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http1.Http1ExchangeCodec$AbstractSource.read(Http1ExchangeCodec.java:389)
at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.http1.Http1ExchangeCodec$UnknownLengthSource.read(Http1ExchangeCodec.java:529)
at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.connection.Exchange$ResponseBodySource.read(Exchange.java:286)
at org.sonarsource.scanner.api.internal.shaded.okio.RealBufferedSource.select(RealBufferedSource.java:100)
at org.sonarsource.scanner.api.internal.shaded.okhttp.internal.Util.bomAwareCharset(Util.java:467)
at org.sonarsource.scanner.api.internal.shaded.okhttp.ResponseBody.string(ResponseBody.java:181)
at org.sonarsource.scanner.api.internal.ServerConnection.downloadString(ServerConnection.java:100)
at org.sonarsource.scanner.api.internal.BootstrapIndexDownloader.getIndex(BootstrapIndexDownloader.java:39)
... 10 more
Caused by: java.net.SocketException: Socket closed
at java.base/sun.nio.ch.NioSocketImpl.endRead(Unknown Source)
at java.base/sun.nio.ch.NioSocketImpl.implRead(Unknown Source)
at java.base/sun.nio.ch.NioSocketImpl.read(Unknown Source)
at java.base/sun.nio.ch.NioSocketImpl$1.read(Unknown Source)
at java.base/java.net.Socket$SocketInputStream.read(Unknown Source)
at org.sonarsource.scanner.api.internal.shaded.okio.Okio$2.read(Okio.java:140)
at org.sonarsource.scanner.api.internal.shaded.okio.AsyncTimeout$2.read(AsyncTimeout.java:237)
... 19 more
From above error, I noticed that it has stuck at the point Download: http://localhost:9000/batch/index , when I browsed this url, noticed that it's trying to find scanner.jar file i.e., sonar-scanner-engine-shaded-10.2.0.77647-all.jar|da07b1882a8a64a25af0bd91f2f62309
Do I need to point this scanner.jar externally ? Definitely, this scanner.jar is missing in my configuration, Can you please help me here ? I really need your assistance. Am I missing anything here ? Any helps here is greatly appreciated.