insideapp-oss / sonar-flutter

SonarQube plugin for Flutter / Dart
Other
449 stars 82 forks source link

java.lang.IllegalStateException: Error while running 'flutter analyze --no-fatal-warnings --no-fatal-infos' (exit 1): 6632 issues found. (ran in 3.3s) #206

Closed paranjay-patel closed 6 months ago

paranjay-patel commented 10 months ago

sonar-scanner command giving below error while scanning flutter application. why its giving this error, what should be the possible solution for the issue. i am using gitlab pipeline.

gitlab-ci

.
.
  script:
    - apt-get update && apt-get install -y openjdk-17-jre
    - curl --create-dirs -sSLo /sonar-scanner-cli.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.6.2.2472.zip
    - unzip -q /sonar-scanner-cli.zip -d /sonar-scanner
    - export PATH=$PATH:/sonar-scanner/sonar-scanner-4.6.2.2472/bin
    - apt-get install -y nodejs
    - apt-get install -y apt-transport-https
    - flutter doctor -v
    - flutter clean
    - flutter pub get
    - dart analyze
    - flutter analyze
    - flutter --version
    - dart --version
    - sonar-scanner

sonar-projects.properties files

sonar.projectKey=pinpoint-fl-app
sonar.projectName=pinpoint-fl-app
sonar.projectVersion=1.0
sonar.sources=lib,pubspec.yaml
sonar.tests=test
sonar.sourceEncoding=UTF-8
sonar.dart.analyzer.options.override=true
sonar.java.binaries= **/*.java
$sonar-scanner
.
.
.

INFO: Restored original analysis_options.yaml file
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 1:43.281s
ERROR: Error during SonarScanner execution
INFO: Final Memory: 28M/108M
INFO: ------------------------------------------------------------------------
java.lang.IllegalStateException: Error while running 'flutter analyze --no-fatal-warnings --no-fatal-infos' (exit 1): 6632 issues found. (ran in 3.3s)
    at fr.insideapp.sonarqube.dart.lang.issues.dartanalyzer.executable.AnalyzerExecutable.maybeThrowException(AnalyzerExecutable.java:103)
    at fr.insideapp.sonarqube.dart.lang.issues.dartanalyzer.executable.AnalyzerExecutable.analyze(AnalyzerExecutable.java:91)
    at fr.insideapp.sonarqube.dart.lang.issues.dartanalyzer.DartAnalyzerSensor.execute(DartAnalyzerSensor.java:67)
    at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:64)
    at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:88)
    at org.sonar.scanner.sensor.ModuleSensorsExecutor.lambda$execute$1(ModuleSensorsExecutor.java:61)
    at org.sonar.scanner.sensor.ModuleSensorsExecutor.withModuleStrategy(ModuleSensorsExecutor.java:79)
    at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:61)
    at org.sonar.scanner.scan.SpringModuleScanContainer.doAfterStart(SpringModuleScanContainer.java:82)
    at org.sonar.core.platform.SpringComponentContainer.startComponents(SpringComponentContainer.java:188)
    at org.sonar.core.platform.SpringComponentContainer.execute(SpringComponentContainer.java:167)
    at org.sonar.scanner.scan.SpringProjectScanContainer.scan(SpringProjectScanContainer.java:403)
    at org.sonar.scanner.scan.SpringProjectScanContainer.scanRecursively(SpringProjectScanContainer.java:[399](https://git.logicwind.co/logicwind/pinpoint/pinpoint-fl-app/-/jobs/24838#L399))
    at org.sonar.scanner.scan.SpringProjectScanContainer.doAfterStart(SpringProjectScanContainer.java:368)
    at org.sonar.core.platform.SpringComponentContainer.startComponents(SpringComponentContainer.java:188)
    at org.sonar.core.platform.SpringComponentContainer.execute(SpringComponentContainer.java:167)
    at org.sonar.scanner.bootstrap.SpringGlobalContainer.doAfterStart(SpringGlobalContainer.java:137)
    at org.sonar.core.platform.SpringComponentContainer.startComponents(SpringComponentContainer.java:188)
    at org.sonar.core.platform.SpringComponentContainer.execute(SpringComponentContainer.java:167)
    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(NativeMethodAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
    at jdk.proxy1/jdk.proxy1.$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)
ERROR: 
ERROR: Re-run SonarScanner using the -X switch to enable full debug logging.
alessandro-mariotti-zupit commented 10 months ago

Hi, I've run in the exact same issue when running sonar-scanner from a docker container.

I had to run flutter pub get before running sonar-scanner, all inside the container where I have installed both flutter (+dart) and sonar scanner.

EDIT: Strangely enough, I'm back on the problem even after flutter pub get. I'll keep you updated if I fix the issue

EDIT 2: Found out.

  1. run flutter pub get before sonar-scanner
  2. make sure your sonar-project.properties file contains the following:
sonar.projectKey=your-project-key
sonar.projectName=your-project-name
sonar.projectVersion=0.0.1

sonar.sourceEncoding=UTF-8
sonar.dart.analyzer.options.override=false
sonar.sources=lib,pubspec.yaml
sonar.tests=test
RAGOpoR commented 10 months ago

I am also facing same issue

07:44:08.826 DEBUG: Analyzer configured for mode: FLUTTER
07:44:08.826 DEBUG: Analyzer configured for output mode: MACHINE
07:44:08.826 INFO: Using existing analysis_options.yaml since override is disabled
07:44:08.826 INFO: Running 'flutter [analyze, --no-fatal-warnings, --no-fatal-infos]'
07:44:11.544 INFO: Command 'flutter analyze --no-fatal-warnings --no-fatal-infos' finished (exit 1)
07:44:11.556 INFO: ------------------------------------------------------------------------
07:44:11.556 INFO: EXECUTION FAILURE
07:44:11.556 INFO: ------------------------------------------------------------------------
07:44:11.557 INFO: Total time: 9.323s
07:44:11.590 INFO: Final Memory: 29M/114M
07:44:11.590 INFO: ------------------------------------------------------------------------
07:44:11.590 ERROR: Error during SonarScanner execution
java.lang.IllegalStateException: Error while running 'flutter analyze --no-fatal-warnings --no-fatal-infos' (exit 1): 314 issues found. (ran in 1.8s)

        at fr.insideapp.sonarqube.dart.lang.issues.dartanalyzer.executable.AnalyzerExecutable.maybeThrowException(AnalyzerExecutable.java:103)
        at fr.insideapp.sonarqube.dart.lang.issues.dartanalyzer.executable.AnalyzerExecutable.analyze(AnalyzerExecutable.java:91)
        at fr.insideapp.sonarqube.dart.lang.issues.dartanalyzer.DartAnalyzerSensor.execute(DartAnalyzerSensor.java:67)
        at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:64)
        at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:88)
        at org.sonar.scanner.sensor.ModuleSensorsExecutor.lambda$execute$1(ModuleSensorsExecutor.java:61)
        at org.sonar.scanner.sensor.ModuleSensorsExecutor.withModuleStrategy(ModuleSensorsExecutor.java:79)
        at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:61)
        at org.sonar.scanner.scan.SpringModuleScanContainer.doAfterStart(SpringModuleScanContainer.java:82)
        at org.sonar.core.platform.SpringComponentContainer.startComponents(SpringComponentContainer.java:201)
        at org.sonar.core.platform.SpringComponentContainer.execute(SpringComponentContainer.java:180)
        at org.sonar.scanner.scan.SpringProjectScanContainer.scan(SpringProjectScanContainer.java:398)
        at org.sonar.scanner.scan.SpringProjectScanContainer.scanRecursively(SpringProjectScanContainer.java:394)
        at org.sonar.scanner.scan.SpringProjectScanContainer.doAfterStart(SpringProjectScanContainer.java:363)
        at org.sonar.core.platform.SpringComponentContainer.startComponents(SpringComponentContainer.java:201)
        at org.sonar.core.platform.SpringComponentContainer.execute(SpringComponentContainer.java:180)
        at org.sonar.scanner.bootstrap.SpringGlobalContainer.doAfterStart(SpringGlobalContainer.java:139)
        at org.sonar.core.platform.SpringComponentContainer.startComponents(SpringComponentContainer.java:201)
        at org.sonar.core.platform.SpringComponentContainer.execute(SpringComponentContainer.java:180)
        at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:71)
        at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:65)
        at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
        at java.base/java.lang.reflect.Method.invoke(Method.java:580)
        at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
        at jdk.proxy1/jdk.proxy1.$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:126)
        at org.sonarsource.scanner.cli.Main.execute(Main.java:81)
        at org.sonarsource.scanner.cli.Main.main(Main.java:62)
sk92129 commented 9 months ago

sonar.dart.analyzer.options.override=false This will help get past the "flutter analyze" step but now I am encountering another error further down. This does not explain why the sonar scanner gets the IllegalStateException.

AntonioZan commented 9 months ago

I also got the same issue, no matter if I change the flag to TRUE or FALSE. This is my properties file:

# Project identification
sonar.projectKey=MyProj
sonar.projectName=MyProj
sonar.projectVersion=1.0
sonar.token=MyToken
sonar.host.url=http://localhost:9000
sonar.sources=.
#lib,pubspec.yaml
#sonar.tests=test
sonar.lang.patterns.dart=**/*.dart
# Encoding of the source code. Default is default system encoding.
sonar.sourceEncoding=UTF-8
sonar.exclusions=test/**/*_test.mocks.dart,lib/**/*.g.dart
sonar.java.binaries= **/*.java

sonar.dart.analyzer.options.override=false

I'm using the SonarQube Common Edition 10.4.

sk92129 commented 9 months ago

somethings that I noticed -- most of my problems went away when I switched the branch to the default branch of GIT.

And I find that the sonarqube does not do much beyond what is already done by "flutter anallyze". Thus, I am not putting much emphasis to get this working further. The sonar-scanner can run to completion and send the reports back to sonarqube. But the results are not that impressive compared to what is already identified by the flutter analyze.

I can share my sonar-project.properties if you DM me

AntonioZan commented 9 months ago

I repeated all the steps today, the only change was the use of the sonar-flutter-plugin-0.5.1-SNAPSHOT.jar instead of the previous sonar-flutter-plugin-0.5.0.jar and it seems to work now. I don't know if this is because I closed and opened the server to do this and maybe something cleaned up, anyway as far as I read the stats, it seems correctly analyzed now.

chardskarth commented 9 months ago

Same experience with @AntonioZan.

My pipeline succeeded without any additional changes in sonar.properties file

santitigaga commented 6 months ago

it would be useful to generate new release with this change @zippy1978

Mshimaz commented 6 months ago

Hi, I've run in the exact same issue when running sonar-scanner from a docker container.

I had to run flutter pub get before running sonar-scanner, all inside the container where I have installed both flutter (+dart) and sonar scanner.

EDIT: Strangely enough, I'm back on the problem even after flutter pub get. I'll keep you updated if I fix the issue

EDIT 2: Found out.

  1. run flutter pub get before sonar-scanner
  2. make sure your sonar-project.properties file contains the following:
sonar.projectKey=your-project-key
sonar.projectName=your-project-name
sonar.projectVersion=0.0.1

sonar.sourceEncoding=UTF-8
sonar.dart.analyzer.options.override=false
sonar.sources=lib,pubspec.yaml
sonar.tests=test

How to run flutter pub get inside the container?

sk92129 commented 6 months ago

Mshimaz --depending on how you run sonarqube, you can add that flutter pub get into your docker script. I usually run my scan from inside an azure devops pipeline (another form of CICD build system from azure) and use a flutter plugin from azure. https://marketplace.visualstudio.com/items?itemName=Hey24sheep.flutter

Mshimaz commented 6 months ago

Mshimaz --depending on how you run sonarqube, you can add that flutter pub get into your docker script. I usually run my scan from inside an azure devops pipeline (another form of CICD build system from azure) and use a flutter plugin from azure. https://marketplace.visualstudio.com/items?itemName=Hey24sheep.flutter

I tried to run the command in the script, but its saying the flutter command is missing. Should I need to install here. If so how can I do that?. Also is there something else I can do to solve the above mentioned error.

zippy1978 commented 6 months ago

Duplicate of https://github.com/insideapp-oss/sonar-flutter/issues/177

zippy1978 commented 6 months ago

Fixed in new release: https://github.com/insideapp-oss/sonar-flutter/releases/tag/0.5.1