Setting Up SonarQube for Code Quality Inspection on Java(Maven/Gradle)/.NET/Python/Go Projects
Anshumaan Singh
Securing Code from Commit to Cloud @ ZEE5 | Engineering Security at the Speed of DevOps | Threat Defense & Cyber Resilience | Cloud-Native Security | Automating Compliance & Proactive Risk Mitigation | CKA | HCTA-003
SonarQube is a powerful tool for continuous inspection of code quality to perform automatic reviews with static analysis of code to detect bugs, code smells, and security vulnerabilities. This guide walks you through setting up SonarQube and integrating it with a Java project using Maven. The instructions are tailored for both Windows and macOS users.
Prerequisites
git clone <your_repo_name>
cd <your_repo_name>
2.Install Java 11: Ensure Java 11 is installed. You can download it from the Java SE 11 Archive Downloads.
Verify the installation:
java -version
3.Install Maven: Download and install Maven from the official website.
Verify the installation:
mvn -version
4.Install Docker Desktop: Download and install Docker Desktop for your operating system.
5.Enable WSL 2 and Virtual Machine Platform (Windows Only): For Windows users, ensure WSL 2 and Virtual Machine Platform features are enabled.
wsl --set-default-version 2
Setting Up SonarQube
1.Download and Run the SonarQube Docker Image: Open a terminal or command prompt and run the following command to download and start the SonarQube Docker container.
docker run -d --name sonarqube -p 9000:9000 -p 9092:9092 sonarqube
Verify the container is running:
docker ps -a
2.Access SonarQube: Open a web browser and navigate to https://localhost:9000. You should see the SonarQube dashboard.
3.Configure SonarQube Project:
领英推荐
Scanning the Java Project
mvn clean verify sonar:sonar \
-Dsonar.projectKey=FirstScanTest \
-Dsonar.projectName='FirstScanTest' \
-Dsonar.host.url=https://localhost:9000 \
-Dsonar.token=<your_sonar_token>
Replace <your_sonar_token> with the token generated from the SonarQube dashboard.
3. View the Scan Results: After the scan completes, go to the SonarQube dashboard (https://localhost:9000) and view the results of the scan. You will see detailed reports on code quality, bugs, vulnerabilities, and code smells.
Results:
Conclusion
By following the steps outlined in this guide, you have successfully set up SonarQube and integrated it with a Java project to perform static code analysis. Regularly scanning your codebase with SonarQube helps maintain high code quality and security, ensuring vulnerabilities and code smells are identified and addressed promptly.
Feel free to customize the steps according to your specific project requirements and environment configurations. Happy coding!
References:
By,
Anshumaan Singh
ZEE Entertainment Enterprises Limited
Securing Code from Commit to Cloud @ ZEE5 | Engineering Security at the Speed of DevOps | Threat Defense & Cyber Resilience | Cloud-Native Security | Automating Compliance & Proactive Risk Mitigation | CKA | HCTA-003
10 个月https://medium.com/@anshumaansingh10jan/setting-up-sonarqube-for-code-quality-inspection-on-java-maven-gradle-net-python-go-projects-5782c17dd64f