Add New Project Sonar

Add New Project Sonar

To keep continue inspection of the code quality Sonar is right tool. It can generate report of coding standard, complexity of the code, potential bugs, unit tests, duplicated code etc…In this demo I will show you how to configure project with Sonar so that we can see generated report. Please follow steps below:

  • First install and start sonar using this tutorial
  • Once Sonar is started you can use its default host and port http://localhost:9000/ to open its console which will look below if no project is configured:

Add New Project Sonar

  • Important thing to note: You won’t find any option to add new project to Sonar from its console. You have to start analysis process, if its done successfully then project will be added automatically to Sonar where you can see its report. There are many ways you could analyze your project and in this tutorial we will be analyzing maven java project.
  • Prerequisites: You have installed and configured maven on your local system. If you have not configured yet please follow this tutorial. For test I have attached one sample maven spring based project which you can download and use for analyzing.
  • Before running maven goal you will have to add below profile setting in maven settings.xml file whose default location is: $MAVEN_HOME/conf or C:\Users\User_name\.m2 directory.

  • Below is complete settings.xml file with default configuration:

  • To analyze maven project you will have to run maven goal sonar:sonar in the current directory where pom.xml file is located. Before runing to Sonar goal you will have to run below maven command:

         mvn clean install
         mvn sonar:sonar

  • Go to command line ( I assume you already set path of maven bin directory to the class path) and run below command:
    Add New Project Sonar

  • Once above command got successful please run mvn sonar goal:

Add New Project Sonar

  • You will sonar goal successful message as below:

  • Important: If you search above console log you will below details SpringMVCJDBCTemplateTutorial is successfully analysed. Now we are ready to its report:

2015-03-11_2328

  • To see project report please open http://localhost:9000/ Sonar console where you will new project got added and to see report click to open it:

Add New Project Sonar

  • On the console you see details project coverage report you can click any link to see details of it:

2015-03-11_2332

  • For more details please visit SonarCube documentation to analyzing the project here

download  Download project: SpringMVCJDBCTemplateTutorial

Leave a Reply

Your email address will not be published. Required fields are marked *