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
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Trending

  • Introducing senro: A Pipeline Engine You Program in Go
  • Kill the Worker, Keep the Research: Build a Recoverable LangGraph Agent on Temporal
  • The Twelve-Factor Agents: Building Production-Ready LLM Applications
  • How to Format Articles for DZone

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

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
·
May. 21, 20 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
5.7K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

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

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • 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