DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Trending

  • The "Zombie API" Attack: Why Your Old Integrations Are Your Biggest Security Risk
  • Stop Using the ATM-Didn’t-Kill-Jobs Story to Reassure Developers About AI
  • AI in Software Development: A Mirror, Not a Magic Wand
  • Spring Boot Done Right: Lessons From a 400-Module Codebase

SonarQube - Static Tool to Analyse and Inspect Code Quality

Take a look at this quick introduction to SonarQube, demonstrating how to set up SonarQube and display metrics using dashboards.

By 
Gowthamraj Palani user avatar
Gowthamraj Palani
·
May. 21, 20 · Tutorial
Likes (3)
Comment
Save
Tweet
Share
5.5K Views

Join the DZone community and get the full member experience.

Join For Free

There are many tools in the testing world to find out bugs and analyze the code after running or execution of the program. Such tools are called dynamic testing tool. There are only few static testing tools that analyze code and give us reports without any execution. We are going to see about one such tool called SonarQube here. Let's see what is it and how to do code inspection in a maven project.

SonarQube

It is an open-source tool used for continuous inspection of code quality. It helps in finding out bugs, code smells, code coverage, and security vulnerabilities. It provides detailed reports on coding standards, unit tests, code coverage, bugs, and security vulnerabilities. 

It supports all major programming languages like Java, Python, Ruby, etc. All supported lanuguages are listed here.

SonarQube with Maven

Let's dive directly to analysis steps in a Java+Maven project. 

Pre-requisites

  • Docker
  • Java
  • Maven

Take a Docker Pull

SonarQube is available as a Docker image. All we need to do is take a pull and start the server in your local. Follow the below steps and start the server. 

Shell
 
x
 
1
docker pull sonarqube:latest
2

          
3
docker container run -d --name sonarqube -p 9000:9000 sonarqube:latest


The server runs in 9000 port. So it is mandatory to start the server in the same port. Now check the SonarQube dashboard here. Wait until you see this screen.
SonarQube

That's it. We are all set to use SonarQube in our project.

Run Scanner

After building your project, run the below command. 

Java
 




xxxxxxxxxx
1


 
1
mvn sonar:sonar



Upon a successful build, you will be able to see these logs. Now as you see in logs, click on reports link to analyze the reports.

Report analysis

Analysis Reports

Bugs, vulnerabilities, code coverage, and security issues are in the dashboard. You can see a detailed report under the issues tab and measures tab.

Overall Code


Issues dashboard

Security Rating


Thanks for reading!! You can find a sample project here.

Opinions expressed by DZone contributors are their own.

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook