Integrating SonarQube with Springboot — Gradle

Athar Majeed
Nov 2, 2020
Photo by Clément H on Unsplash

The easiest way to set up Sonar on localhost is by using Docker. You can also configure by downloading the zip file. However, I’m going to use Docker for the post.

Let’s get started!

  1. Download (if not already) and start the Docker on your computer
  2. Download the Sonar image from here or you can run the following command from the terminal docker pull sonarqube
  3. Run the following command in your terminal, if this is successful then browse to this URL from your web browser http://localhost:9000/
docker run -d --name sonarqube -e SONAR_ES_BOOTSTRAP_CHECKS_DISABLE=true -p 9000:9000 sonarqube:latest

The default username and password is ‘admin’.

  • Once you login then you can create a new project from the top right + button
  • Enter the project key (without spaces)and a display name
  • On the next screen, generate a token with a name.

Now, we will make two changes to our project as highlighted in the image below.

  1. This is where we are setting up our project with Sonarqunbe. We are updating the build.gradle file with a sonarQube plugin.
  2. Run the second or following command (make sure to change the param values) from the (project directory) terminal
./gradlew pitest sonarqube \
-Dsonar.projectKey=api \
-Dsonar.host.url=http://localhost:9000 \
-Dsonar.login=82094cecd3404a183e96d778b647cd68eb0

Once the project builds successfully then we should be able to see the results in the web browser at http://localhost:9000/

Notes:

  1. https://docs.sonarqube.org/latest/setup/get-started-2-minutes/

--

--

Athar Majeed

Tech Entrepreneur | Software Engineer | Co-Founder | Cloud Enthusiastic.