Start SonarQube server using Docker
docker run -d -p 9000:9000 --name sonarqube sonarqube:latest
Install Java
Check if you have java installed in your system
java -version
We need java verison 11 to run the sample code, you can use below command to install the java 11.
sudo apt-get install default-jdk
If you have multiple java versions installed, you can used below command to slect the java version 11 for this project.
sudo update-alternatives --config java
Install Maven
Visit https://maven.apache.org/download.cgi page to download the Maven or you can use below command to download it from the command line.
wget https://dlcdn.apache.org/maven/maven-3/3.8.6/binaries/apache-maven-3.8.6-bin.tar.gz
Extract tar file and then goto bin directory.
tar -xvzf apache-maven-3.8.6-bin.tar.gz
cd apache-maven-3.8.6/bin
Run pwd
command to get the maven bin directory path
pwd
My output:
/home/ishtiyaq/Downloads/apache-maven-3.8.6/bin
Set the maven path in the system PATH
variable.
export PATH="$PATH:/home/ishtiyaq/Downloads/apache-maven-3.8.6/bin"
Now, you will be able to access the mvn
command from anywhere in your system.
sudo apt install git
Now, goto your desktop and clone the sample project.
git clone https://github.com/ishtiyaq-td/sonar-demo.git
Go to the project directory,
cd sonar-demo
Login to your sonarqube server and crate a project.
SonarQube default username and password is
admin
# Required metadata
sonar.projectKey=sonar-demo
sonar.projectName=Simple Java project analyzed with the SonarQube Runner
sonar.projectVersion=1.0
# Comma-separated paths to directories with sources (required)
sonar.sources=src
# Language
sonar.language=java
# Encoding of the source files
sonar.sourceEncoding=UTF-8
mvn compile
mvn clean verify sonar:sonar \
-Dsonar.projectKey=<your-project-key> \
-Dsonar.host.url=<your-sonarqube-server-url> \
-Dsonar.login=<your-sonarqube-access-key>