Fail to scan Dart/Flutter project on GitLab CI

Great to see that Dart is now supported. I am new to Sonarcloud and I am trying to setup a flutter project using gitlab ci. I have done the default tutorial setting up a .gitlab-ci.yml. But I am getting errors first I got errors when it tried to analyse C and C++ code. I added sonar.c.file.suffixes=- sonar.cpp.file.suffixes= -sonar.objc.file.suffixes=- to my properties file to ignore this. But now I am getting another error. Error during SonarScanner execution

[216](https://gitlab.com/civinc/civinc-chat/-/jobs/7863718586#L216)java.lang.IllegalStateException: java.io.IOException: Cannot run program "/builds/civinc/civinc-chat/.scannerwork/.sonartmp/8994351846903738207/bin/sonar.exe": error=2, No such file or directory
[217](https://gitlab.com/civinc/civinc-chat/-/jobs/7863718586#L217) at com.sonarsource.dart.plugin.Analyzer.<init>(Analyzer.java:87)

I feel like I am missing an important part, but I am very new to this. Any Idea what I might be doing wrong? Is there a tutorial somewhere that I can follow to get it to work?

Hello @Jochem_Toolenaar,

Thanks for your feedback.

I will need some additional information.

Could you please share your configuration and the environment of the analysis and how exactly you perform it? The sonar analysis step from your .gitlab-ci.yml will help.

Another question, have you tried analyzing the project locally? If yes, do you see the same results?

Best,
Margarita

We managed to reproduce your issue.

This is related to the fact that in the tutorial we’re referencing sonarsource/sonar-scanner-cli:latest image which is Alpine-based and not supported officially by Dart.

The workaround is, instead of using this image, download the sonar-scanner directly in the script and execute the analysis. Here you can find an example:

          export SONAR_SCANNER_VERSION=6.1.0.4477
          export SONAR_SCANNER_HOME=$HOME/.sonar/sonar-scanner-$SONAR_SCANNER_VERSION-linux-x64
          curl --create-dirs -sSLo $HOME/.sonar/sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-$SONAR_SCANNER_VERSION-linux-x64.zip
          unzip -o $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/
          export PATH=$SONAR_SCANNER_HOME/bin:$PATH
          export SONAR_SCANNER_OPTS="-server"
          sonar-scanner \
            -Dsonar.organization=your_org \
            -Dsonar.projectKey=your_project_key\
            -Dsonar.sources=. \
            -Dsonar.host.url=https://sonarcloud.io 

Note, in order to have a proper analysis experience, don’t forget to get dependencies (flutter pub get) and build the project before executing the analysis.

Meanwhile we’ll work on a proper solution and will update the tutorials.

Best,
Margarita

1 Like

Thanks! I got it to work with the following script.

stages:
  - setup

# Job to set up Flutter project
setup_flutter:
  stage: setup
  image: ghcr.io/cirruslabs/flutter:3.24.3
  script:
    - flutter pub get
    - export SONAR_SCANNER_VERSION=6.1.0.4477
    - export SONAR_SCANNER_HOME=$HOME/.sonar/sonar-scanner-$SONAR_SCANNER_VERSION-linux-x64
    - curl --create-dirs -sSLo $HOME/.sonar/sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-$SONAR_SCANNER_VERSION-linux-x64.zip
    - unzip -o $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/
    - export PATH=$SONAR_SCANNER_HOME/bin:$PATH
    - export SONAR_SCANNER_OPTS="-server"
    - sonar-scanner -Dsonar.organization= your_org -Dsonar.projectKey=your_project_key -Dsonar.sources=. -Dsonar.host.url=https://sonarcloud.io
2 Likes