Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      CodeSOD: A Unique Way to Primary Key

      July 22, 2025

      BrowserStack launches Figma plugin for detecting accessibility issues in design phase

      July 22, 2025

      Parasoft brings agentic AI to service virtualization in latest release

      July 22, 2025

      Node.js vs. Python for Backend: 7 Reasons C-Level Leaders Choose Node.js Talent

      July 21, 2025

      The best CRM software with email marketing in 2025: Expert tested and reviewed

      July 22, 2025

      This multi-port car charger can power 4 gadgets at once – and it’s surprisingly cheap

      July 22, 2025

      I’m a wearables editor and here are the 7 Pixel Watch 4 rumors I’m most curious about

      July 22, 2025

      8 ways I quickly leveled up my Linux skills – and you can too

      July 22, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      The Intersection of Agile and Accessibility – A Series on Designing for Everyone

      July 22, 2025
      Recent

      The Intersection of Agile and Accessibility – A Series on Designing for Everyone

      July 22, 2025

      Zero Trust & Cybersecurity Mesh: Your Org’s Survival Guide

      July 22, 2025

      Execute Ping Commands and Get Back Structured Data in PHP

      July 22, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      A Tomb Raider composer has been jailed — His legacy overshadowed by $75k+ in loan fraud

      July 22, 2025
      Recent

      A Tomb Raider composer has been jailed — His legacy overshadowed by $75k+ in loan fraud

      July 22, 2025

      “I don’t think I changed his mind” — NVIDIA CEO comments on H20 AI GPU sales resuming in China following a meeting with President Trump

      July 22, 2025

      Galaxy Z Fold 7 review: Six years later — Samsung finally cracks the foldable code

      July 22, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»Development»How to improve your code quality with SonarQube

    How to improve your code quality with SonarQube

    May 2, 2025

    SonarQube is a powerful open-source tool that helps you maintain code quality and security by analyzing your codebase for bugs and vulnerabilities. And it can play a major role when integrated into your CI/CD pipeline.

    In this tutorial, we will cover:

    1. What is SonarQube?

    2. How SonarQube Improves Code Quality

    3. Step-by-step Installation and Configuration

    4. How to Run Your First Code Analysis

    What is SonarQube?

    SonarQube is an open-source tool that checks for code quality continuously. It analyzes code to find issues like duplication, bad practices, test coverage gaps, bugs, and vulnerabilities, giving detailed reports. It works with many programming languages like Java, C#, JavaScript, Python, TypeScript, and Kotlin.

    You can add SonarQube to your CI/CD pipelines, IDEs, and version control systems like GitHub, GitLab, or Bitbucket. It provides detailed dashboards that show metrics, trends, and issues in your code.

    You can use custom rules to enforce coding standards and reduce technical debt. SonarQube also supports code coverage analysis to help teams improve their tests. With the Quality Gate feature, teams can ensure only clean, maintainable code goes into production.

    SonarQube offers both free and paid versions to suit any team size. Overall, it helps improve software quality and encourages good coding practices.

    How Does SonarQube Improve Code Quality?

    Here’s how SonarQube helps improve code quality:

    1. Early bug detection: Identifies bugs before they reach production

    2. Improved maintainability: Highlights code and design issues

    3. Security insights: Identifies vulnerabilities and security risks

    4. Code coverage: Integration with testing tools to monitor unit test coverage

    5. Customizable rules: Allows teams to set coding standards and policies

    6. Team collaboration: Ensures consistent code quality across development teams

    Step-by-Step Installation and Configuration

    Prerequisites:

    Here are the prerequisites that you will need before installing SonarQube

    1. Java Runtime Environment(JRE): Java 11 or above installed in your system.

    2. System Requirements: 2GB RAM minimum (Recommended: 4GB+).

    3. MacOS: You can use HomeBrew, which is the package manager for MacOS that simplifies the installation of software.

    Below are the steps to install SonarQube in your local machine:

    Download SonarQube

    Download the software from sonarsource downloads and choose the Community Edition for open-source projects.

    Extract and Configure

    To install SonarQube, you need to run the below command to unzip the file:

    unzip sonarqube-<version>.zip
    cd sonarqube-<version>/bin/<your-OS-folder>
    

    Start SonarQube

    On Linux/Mac, you need to run the below command:

    ./sonar.sh start
    

    On Windows, you need to run this one:

    StartSonar.bat
    

    Access SonarQube

    To access SonarQube, you need to open browser and go to: http://localhost:9000

    Enter the default credentials:

    • Username: admin

    • Password: admin (you’ll be prompted to change it)

    The page will look similar to below:

    SonarQube project creation page

    Set Up SonarQube in Your Project

    To set up SonarQube in your project, start by opening the Java project on your machine. In the project root, create a sonar-project.properties file.

    Add the below key value pairs in the file:

    sonar.projectKey=spring-myproject
    sonar.projectName=My Project
    sonar.projectVersion=1.0
    sonar.sources=.
    sonar.host.url=http://localhost:9000
    

    How to Run Your First Code Analysis

    Configure and Run SonarScanner

    SonarScanner is the tool that actually sends your code to SonarQube for analysis. Below are the detailed steps to follow to use it:

    Install SonarScanner:

    On Windows/Linux, download the software from SonarSource and unzip it:

    unzip sonar-scanner-cli-<version>.zip
    

    On MacOS, run the below command:

    >brew install sonar-scanner
    

    For both Windows/Linux and MacOS, verify the install by running the below command:

    >sonar-scanner -v
    

    Configure SonarScanner

    After installing SonarScanner, you’ll need to configure it by setting the SonarQube server URL and authentication token. Then go to your SonarQube profile (top-right corner > My Account > Security) and generate a token.

    Generate tokens in SolarQube

    Provide a name for the token and click ‘Generate’:

    Name token and then generate

    In the sonar-project.properties file in your project, add ‘sonar.login’ property and save.

    sonar.projectKey=test-project
    sonar.projectName=Test Project
    sonar.host.url=http://localhost:9000
    sonar.login=<YOUR_TOKEN_HERE>
    

    Run the Analysis

    Once the SonarScanner is configured, you can start scanning your project.

    In a terminal or command prompt, go to the root of your project (where sonar-project.properties is located).

    Run the following command:

    >sonar-scanner
    

    SonarScanner will analyze your code and push the results to your local SonarQube server. Visit http://localhost:9000, and you’ll see your project listed on the dashboard.

    • Scanner results dashboard

    To view the analysis report, go to http://localhost:9000/dashboard?id=java-sonar-demo:

    Analysis results

    If you go to the ‘Issues’ tab at top left corner, you can view different categories of Software Quality, Severity of the Issues, and various other attributes in your code.

    Detailed results

    Conclusion

    Now you have installed and configured SonarQube and learned how to scan your code using SonarScanner. You can easily configure it in your projects for continuous code quality analysis.

    This is a fantastic tool for keeping your code base clean and maintainable. As the next steps, you can consider adding test coverage reports, enforcing quality gates in your pipeline, and exploring SonarCloud for cloud-based analysis.

    ##

    Source: freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleAPI Documentation: The Importance of Clear and Concise API Documentation
    Next Article Learn Kubernetes – Full Handbook for Developers, Startups, and Businesses

    Related Posts

    Development

    GPT-5 is Coming: Revolutionizing Software Testing

    July 22, 2025
    Development

    Win the Accessibility Game: Combining AI with Human Judgment

    July 22, 2025
    Leave A Reply Cancel Reply

    For security, use of Google's reCAPTCHA service is required which is subject to the Google Privacy Policy and Terms of Use.

    Continue Reading

    Do We Still Need Complex Vision-Language Pipelines? Researchers from ByteDance and WHU Introduce Pixel-SAIL—A Single Transformer Model for Pixel-Level Understanding That Outperforms 7B MLLMs

    Machine Learning

    CVE-2025-41646 – Apache Software Type Confusion Authentication Bypass

    Common Vulnerabilities and Exposures (CVEs)

    Overwatch 2’s Gundam Wing crossover event has been fully revealed with a new trailer

    News & Updates

    CVE-2025-43565 – ColdFusion Incorrect Authorization Arbitrary Code Execution

    Common Vulnerabilities and Exposures (CVEs)

    Highlights

    CVE-2025-44193 – SourceCodester Simple Barangay Management System SQL Injection

    April 30, 2025

    CVE ID : CVE-2025-44193

    Published : April 30, 2025, 6:15 p.m. | 53 minutes ago

    Description : SourceCodester Simple Barangay Management System v1.0 has a SQL injection vulnerability in /barangay_management/admin/?page=view_complaint.

    Severity: 0.0 | NA

    Visit the link for more details, such as CVSS details, affected products, timeline, and more…

    CVE-2025-7077 – Shenzhen Libituo Technology LBT-T300-T310 Buffer Overflow Vulnerability

    July 7, 2025

    Ready to ditch Windows? ‘End of 10’ makes converting your PC to Linux easier than ever

    June 20, 2025

    Commvault Confirms Hackers Exploited CVE-2025-3928 as Zero-Day in Azure Breach

    May 11, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.