Sonarqube Demo / Java Config

June Chung
3 min readAug 13, 2020

--

Sonarqube Demonstration is performed by using docker

<Prerequisite>
Need participants to install docker on their laptop (windows — need to install docker software, linux based — can download easily by package manager)

###CF. How to install docker on CentOS
yum install -y wget
wget <docker package link>
yum install <package downloaded>
docker pull image sonarqube:latest
curl -fsSL https://get.docker.com/ | sh

sudo systemctl start docker

sudo systemctl status docker

sudo systemctl enable docker
(enable for docker for every reboot)

sudo usermod -aG docker $(whoami)
OR sudo usermod -aG docker username

>> Start Docker Service

>> Pull sonarqube image from docker hub
docker pull sonarqube:latest
Check if the image pulled successfully : docker image ls

>> Run Sonarqube image as a container
docker container run -d --name sonarqube -p 9000:9000 sonarqube:latest

>> Clone the project in to local
git clone https://github.com/1junechung/PetClinic.git

>> Browser go to localhost:9000
You will be able to see the main page

>> login
initial id/pw — admin/admin
>>create a project “sample”
>>create the token — enter “sample” and generate token
dfd18170e2a92a9c29041d15510e1cb3f6075ebd (is my token 13-Aug)

>> select Java(programming language) & Maven (Build Tool)

IN CASE — if you don’t have maven downloaded
go to https://maven.apache.org/download.cgi and download “link” — apache-maven-3.6.3-bin.tar.gz
> cd /opt
> wget “paste in the link from the above uri”
> ls (to the extracted directory)
>>Unzip the file
> tar zxf <downloaded zipped file.gz>

* To check mvn installed correctly : mvn -v

export PATH=$PATH:/opt/apache-maven-3.6.2/bin

>> Create a sonarqube properties file in the project directory
vi sonar-project.properties

>> Build the project (Build First)
mvn compile

>> Run the sonarqube executable command
mvn sonar:sonar \
-Dsonar.projectKey=sample \
-Dsonar.host.url=http://localhost:9000 \
-Dsonar.login=dfd18170e2a92a9c29041d15510e1cb3f6075ebd

*** Sometimes this doesn’t work when the lines are entered

CF. How to change Java Version in your local environment
/usr/libexec/java_home -V
export JAVA_HOME=`/usr/libexec/java_home -v <version you want>`
(Changing the Java Home directory)

>> Then you will be able to see the reports http://localhost:9000

#### How to use Maven Wrapper (mvnw)
This is to make build/compile easier, in case user does not have java installed or mvn version difference. This wrapper file configures, downloads the required java and mvn for them

What does mvn “clean” install do ?
Deletes all the files in /target repository and builds again

Build is a bigger concept than compile

--

--