Starting SonarQube, and using Sonar Scanner

Starting SonarQube:

docker-compose up -d

Open SonarQube in browser at http://localhost:9000/

  • Login: admin
  • Password: admin

Open security page and generate a token at http://localhost:9000/account/security/

Clone git repo (java projects)

git clone https://github.com/SonarSource/sonar-scanning-examples.git

Generate Jacoco report

cd sonar-scanning-examples\sonarqube-scanner-maven\maven-basic
mvn clean verify

Install Sonar scanner

#Configure here general information about the environment, such as SonarQube server connection details for example
#No information about specific project should appear here

#----- Default SonarQube server
sonar.host.url=http://localhost:9000

#----- Default source code encoding
sonar.sourceEncoding=UTF-8

sonar.login=<Your generated token in SonarQube>
sonar.projectKey=<project key>
sonar.projectName=<project name>
sonar.coverage.jacoco.xmlReportPaths=./sonar-scanning-examples/sonarqube-scanner-maven/maven-basic/target/site/jacoco/jacoco.xml
sonar.scm.provider=git
sonar.projectBaseDir=./sonar-scanning-examples
sonar.sources=./sonarqube-scanner-maven/maven-basic/src
sonar.coverage.exclusions=**/src/test/**/*.java
sonar.java.binaries=./sonarqube-scanner-maven/maven-basic/target/classes
sonar.java.test.binaries=./sonarqube-scanner-maven/maven-basic/target/test-classes
sonar.java.libraries=./sonarqube-scanner-maven/maven-basic/target

Run Sonar scanner

cd sonar-scanner-4.7.0.2747-windows\bin
sh sonar-scanner

Check new project in SonarQube

Shutdown down the containers, network, and volumes

docker-compose down -v

References: