Use SonarQube for Code Inspection

Search for a command to run...

No comments yet. Be the first to comment.
In this article, we'll write a JUnit Test configured with Environment Variables using junit-pioneer library. First of all, we need to add the junit-pioneer library and maven-surefire-plugin to the Maven pom.xml. <project> <properties> <p...
Problem The problem occurs when using the Python requests library, the chardet library is not installed. /Users/adacheng/Library/Python/3.9/lib/python/site-packages/requests/__init__.py:86: RequestsDependencyWarning: Unable to find acceptable charact...

Apache Kafka is an open-source distributed event streaming platform for high-performance data pipelines, streaming analytics, data integration, and mission-critical applications. Introduction This article aims to provide basic hands-on instructions ...

Problem When AWS STS module is included in a Spring Boot Application, exception complaining region not set is thrown. Maven pom.xml <dependency> <groupId>software.amazon.awssdk</groupId> <artifactId>sts</artifactId> </dependency> Error M...

Installation Follow the instruction in this article to install Trivy. Scan To scan the docker image: Build the image. docker build . -t hello-world Scan the image. trivy scan hello-world

SonarQube is a great code inspection tool for code quality and code security. It provides Docker image for easy setup of the server, and Maven plugin for code inspection.
Install SonarQube from Docker image.
docker run -d --name sonarqube \
-e SONAR_ES_BOOTSTRAP_CHECKS_DISABLE=true \
-p 9000:9000 sonarqube:latest
docker restart sonarqube
Once the instance is up and running, log in to http://localhost:9000 using System Administrator credentials:
login: admin
password: admin
Generate a token.
i. From the menu at top right corner, click "My Account".

ii. Select the "Security" tab.

iii. In the "Tokens" section, enter Token Name and click the "Generate" button.

Add Maven plugin in pom.xml.
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.9.1.2184</version>
</plugin>
</plugins>
</pluginManagement>
</build>
Run analysis using the following command:
export PROJECT_KEY=hello-world
export SONAR_URL=http://localhost:9000
export SONAR_TOKEN=74747088e1eb4cb74efd2495f351b5125214b74e
mvn clean verify sonar:sonar \
-Dsonar.projectKey=$PROJECT_KEY \
-Dsonar.host.url=$SONAR_URL \
-Dsonar.login=$SONAR_TOKEN
Check the result via the admin console.
