5.1 Simple Analysis using SonarScanner

Below is the basic code to create the sonar-project.properties file to compile the code and analyse it.

#Required metadata
sonar.projectKey=org.sonarqube:<ProjectName>
sonar.projectName=Java :: Test Project:: SonarQube Scanner
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

* - REPLACE WITH APPROPRIATE CONTENTS FOR THE LINES WITH ANGULAR BRACES <>

If you want to validate the project then first you must navigate to the project folder in command prompt and hit the following command

sonar-scanner

The above command requires the sonar-project.properties file to be available in the project location otherwise it gives error messages.After saving the above code try to run the code using the following lines

  1. If you haven't set the environment variables then run using the following commands

cd C:\<workspace location>\<ProjectName>\sonar-project.properties C:\<sonar-scanner-installation directory>\bin\sonar-scanner.bat

  1. If you have set the environment variables set for sonar scanner then type the following command

sonar-scanner sonar-tester.properties

After we get a success message we can view it in the dashboard of sonarQube.

Last updated