Skip to content

ishtiyaq-td/sonar-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SonarQube Demo

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.

Install git and clone the sample project from the given link

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

Create a project on SonarQube server

Login to your sonarqube server and crate a project.

SonarQube default username and password is admin

Configure sonar-project.properties and connect maven to SonarQube

# 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

Compile the code

mvn compile

Run the SonarQube scanner

mvn clean verify sonar:sonar \
  -Dsonar.projectKey=<your-project-key> \
  -Dsonar.host.url=<your-sonarqube-server-url> \
  -Dsonar.login=<your-sonarqube-access-key>

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages