Setup SonarQube locally for android
SonarQube is a powerful open-source platform designed to continuously inspect and improve code quality throughout the software development process. Originally known as Sonar, this tool has evolved into a comprehensive solution for managing and enhancing the quality of codebases. By providing static code analysis, automated code review, and continuous inspection capabilities, SonarQube assists development teams in maintaining high standards of code quality, identifying and fixing issues early in the development lifecycle.
By integrating SonarQube into the development workflow, teams can foster a culture of continuous improvement, delivering higher quality software with fewer defects and improved maintainability. It plays a crucial role in helping organizations achieve their goals of delivering reliable and efficient software products.
Setting Up SonarQube Server on macOS Using Docker
Prerequisites:
Before installing SonarQube on your Mac, ensure that Docker Desktop is installed. Follow the steps below:
- Download Docker Desktop for Mac from the official Docker website.
- If you have an M1/M2 chip, download Docker Desktop for Mac with Apple silicon
- If you have an Intel chip, download Docker Desktop for Mac with Intel chip
2. After the download is complete, open your Mac terminal and verify the Docker installation by typing:
docker --version
You should see the installed version of Docker.
Installing SonarQube:
- Pull the latest SonarQube image into Docker using the following command:
docker pull sonarqube:latest
Launch Docker from Applications. You should now see SonarQube in Images -> Local -> Sonarqube
.
Alternatively, you can check if SonarQube is running using:
docker ps -a
Starting SonarQube Server:
- Start the SonarQube server with the following command:
docker run -d --name sonarqube -p 9000:9000 sonarqube
- Once the server is running, open your browser and navigate to http://localhost:9000/.
- You’ll be prompted for a username and password.
- Use
admin
for both fields and log in.
Configuring SonarQube:
- On the SonarQube homepage, create a project and set it up locally.
- while creating project make sure to give the same package name of your application
- During project creation, a Sonar token will be generated. Copy and save it for use in your project.
Once the project is created you should add the below line to your build.gradle
plugins {
id "org.sonarqube" version "4.4.1.3373"
}
Now sync the project and run the following command
./gradlew sonar \
-Dsonar.projectKey=TestApp \
-Dsonar.projectName='TestApp' \
-Dsonar.host.url=http://localhost:9000 \
-Dsonar.token=sqp_token
Following these steps, you’ll have SonarQube up and running on your Mac using Docker. This allows you to perform continuous code quality analysis and enhance the overall quality of your software projects.