Step 1: Installation of SonarQube Server
1. Download SonarQube CE - https://www.sonarqube.org/
| SonarQube |
2. Extract SonarQube and navigate to - <install_director>/sonarqube-6.7.3/bin/windows-x86-64
| SonarQube Windows Launcher |
Note you find different *.bat file such as InstallNTService.bat, StartNTService.bat, StartSonar.bat etc.
3. Configure Path - Copy the path of this folder which may look like <install_director>/sonarqube-6.7.3/bin/Windows-x86-64 (in case of my laptop), and append it to “Path” environment variable.
4. Open a command prompt, type “StartSonar” command and execute. This would start a web server at default port of 9000. This will ensure Sonar Environment is set correctly.
5. Open a web browser and access the page, http://localhost:9000. This means that you have been able to successfully start your SonarQube server. Lets move further to analyze project.
6. For quick setup and testing purpose, you may live with embedded database. However, for production and real usage, one may want to use production-read databases such as MySQL, Oracle etc. For configuration instructions, edit <install_directory>/conf/sonar.properties to configure the database settings.
Step 2: Installation of Code Analyzer -Sonar Runner/ Sonar Scanner Plugins
1. Install Sonar Scanner from - https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner or
http://repo1.maven.org/maven2/org/codehaus/sonar/runner/sonar-runner-dist/2.4/sonar-runner-dist-2.4.zip
2. Unzip the file to appropriate location
3. Setup the SONAR_RUNNER_HOME environment variable and assign it to SonarRunner installation directory
4. Add the <sonarrunner_install_directory>/bin directory to your path.
Check the basic installation by opening a new shell and executing the command sonar-runner -h (on Windows platform the command is sonar-runner.bat -h).
If above get executed, you are all set to analyze your first project with SonarQube runner.
3. Update the global settings to point to your SonarQube server by editing <install_directory>/conf/sonar-scanner.properties:
6. For quick setup and testing purpose, you may live with embedded database. However, for production and real usage, one may want to use production-read databases such as MySQL, Oracle etc. For configuration instructions, edit <install_directory>/conf/sonar.properties to configure the database settings.
Step 2: Installation of Code Analyzer -Sonar Runner/ Sonar Scanner Plugins
1. Install Sonar Scanner from - https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner or
http://repo1.maven.org/maven2/org/codehaus/sonar/runner/sonar-runner-dist/2.4/sonar-runner-dist-2.4.zip
2. Unzip the file to appropriate location
3. Setup the SONAR_RUNNER_HOME environment variable and assign it to SonarRunner installation directory
4. Add the <sonarrunner_install_directory>/bin directory to your path.
Check the basic installation by opening a new shell and executing the command sonar-runner -h (on Windows platform the command is sonar-runner.bat -h).
If above get executed, you are all set to analyze your first project with SonarQube runner.
3. Update the global settings to point to your SonarQube server by editing <install_directory>/conf/sonar-scanner.properties:
#----- Default SonarQube server
#sonar.host.url=http://localhost:9000
Add the <install_directory>/bin directory to your path.
You can verify your installation by opening a new shell and executing the command sonar-scanner -h (on Windows platform the command is sonar-scanner.bat -h).
Step 3: Analysis of SBT Project
1. Create a configuration file in the root directory of the project, namely, sonar-project.properties
2. Add Sonar Plugins and Enable the Build with Sonar Extensions.
Navigate to Project Structure
Add Following Plugins in plugins.sbt -
3. Open a command prompt, and go to project root folder.
4. Execute "sbt sonar" command to run the analysis. You would see the analysis run.
5. Go to the browser and access the page, http://localhost:9000
6. You would find your project listed under “PROJECTS”. Click on your project listing and you would land up on the project dashboard.
1. Create a configuration file in the root directory of the project, namely, sonar-project.properties
2. Add Sonar Plugins and Enable the Build with Sonar Extensions.
Navigate to Project Structure
Add Following Plugins in plugins.sbt -
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.5.14")addSbtPlugin("de.johoop" % "jacoco4sbt" % "2.1.6")addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "1.0.0")addSbtPlugin("com.aol.sbt" % "sbt-sonarrunner-plugin" % "1.0.4")addSbtPlugin("com.artima.supersafe" % "sbtplugin" % "1.1.3")
Enable Sonar in build.sbt -
enablePlugins ( SonarRunnerPlugin )
3. Open a command prompt, and go to project root folder.
4. Execute "sbt sonar" command to run the analysis. You would see the analysis run.
5. Go to the browser and access the page, http://localhost:9000
6. You would find your project listed under “PROJECTS”. Click on your project listing and you would land up on the project dashboard.
| Sonar Dashboard |
Additional Settings
Configuration
To use specific Sonar settings, add the following to your build.sbt file:
sonarProperties ++= Map(
"sonar.host.url" -> "http://hostname.com",
"sonar.jdbc.username" -> "sonar",
"sonar.jdbc.password" -> "sonar",
"sonar.coverage.exclusions" -> "**/AppController.java,**/SomeClass.java"
)
You can also specify the following sonar-runner options:
-D,--define <arg> Define property
-e,--errors Produce execution error messages
-h,--help Display help information
-v,--version Display version information
-X,--debug Produce execution debug output
sonarRunnerOptions := Seq("-e", "-X")
Run Sonar
sbt sonar