At the time of this writing there was no clear, straight forward way to add SonarQube’s (https://www.sonarqube.org/) static code analysis tool to your Flutter code.

In this article, I’ll provide step-by-step instructions on how to install Docker, modify its state, save your container as an image, add SonarQube’s SonarScanner and run analysis on your code.

A machine running MacOS was used during this tutorial.

Prerequisites:

1. Download Docker

Docker is a tool designed to make it easier to create, deploy, and run applications by using containers. Containers allow developers to package an application with all of the parts it needs, such as libraries and other dependencies, and deploy it as a single package.

Download: https://docs.docker.com/engine/install/

After downloading, ensure you are logged in and leave it running.

if you are experiencing problems try:

- docker logout

_docker login — username — password  _https://hub.docker.com

or

docker login

2. Download the SonarScanner Flutter Plugin

At the time of this writing, there were no official support for Dart on SonarScanner but luckily for now there’s a plugin that can help us with that

After downloading the “sonar-flutter-plugin-0.2.1.jar” file, paste it on the root of your Flutter project

Download : https://github.com/insideapp-oss/sonar-flutter

3. Create SonarQube’s Project Properties file

In the root directory of your Flutter project create “sonar-project.properties” and add the following:

# must be unique in a given SonarQube instance

sonar.projectKey=fluttertemplate

sonar.projectName=fluttertemplate

sonar.projectVersion=1.0

# Path is relative to the sonar-project.properties file. Defaults to

sonar.sources=lib

sonar.tests=test

# Encoding of the source code. Default is default system encoding

sonar.sourceEncoding=UTF-8

# Exclude spec files for coverage tests

#sonar.exclusions=lib/test

4. Download SonarScanner for your OS

After downloading, extract the file to an easily accessible path and add sonar-scanner to your system path so it can be accessed from the terminal:

$PATH_TO_SONAR-SCANNER/sonar-scanner-4.4.0.2170-macosx/bin

Download: https://docs.sonarqube.org/latest/analysis/scan/sonarscanner/

5. Create a base container

run:

docker create — name sonarqubebase -p 9000:9000 sonarqube

This will create a container called sonarqubebase with sonarqube (https://hub.docker.com/_/sonarqube) as it’s base image with port 9000 exposed

Inspect images : docker images

Inspect containers: docker ps -a

6. Start the container

run: docker sonarqubebase

#sonarqube #flutter

Integrating SonarQube to your Flutter App using Docker
32.65 GEEK