Configuring Sonar In Your Window’s Desktop

1.  Install Sonar Server In Windows

In order to connect sonar maven plugin and/or sonar eclipse plugin to the local sonar server (for example in windows PC), you need to install the sonar server.

Here are the steps :

  • Download and unpack the sonar server zip file from here.
  • Start sonar server:

          bin\windows-x86-32\StartSonar.bat  (for 32 bit Windows)

  • Open Sonar admin page “http://localhost:9000“. Default credentials – admin/admin
  • Either create a new sonar profile by importing all rules files –                                                                                                               (a) Edit configuration given in top right web page: Configuration-> Create . Enter a profile name and select Checkstyle, Findbugs and PMD configuration files.

          (b) Click “Create” and set the new profile as default

  • Or restore the configuration from a backup – Configuration->System->Backup->Restore configuration.

2.  Install Sonar plugin in the Eclipse IDE

  • Help> Install New Software
  • Paste “http://dist.sonar-ide.codehaus.org/eclipse/ into the field named “Work with:” and press Enter.
  • Select: “Sonar Integration for Eclipse..
  • Click Next. Eclipse will then check to see if there are any issues which would prevent a successful installation.
  • Click Finish to begin the installation process. Eclipse will then download and install the necessary components.
  • Once the installation process is finished, Eclipse will ask you if you want to restart the IDE. It’s strongly recommended that you restart IDE.

3.  Eclipse Configuration After Sonar plugin installation

    (a) Server Configuration In Eclipse:-

  • Window > Preferences > Sonar
  • Add
  • Check if Sonar server lists shows a link like  http://localhost:9000. If it doesn’t then add the link as New Sonar Server Connection > Sonar Server URL.
  • Default credentials: admin/admin
  • Click Test Connection . (will get Successfully connected popup)
  • Ok …
  • Finish
  • Apply
  • Ok

   (b) Download “clover.licence” file from here. This is a FREE TRIAL VERSION and it is valid for only 30 days.

   (c) Edit the pom.xml of the maven project to include the below for which you need to run the sonar. Edit proper “licenceLocation” field.


<plugin>

<groupId>com.atlassian.maven.plugins</groupId>

<artifactId>maven-clover2-plugin</artifactId>

<version>2.6.3</version>

<configuration>

<licenseLocation>Give the absolute location of the “clover.license” file</licenseLocation>

</configuration>

<executions>

<execution>

<phase>verify</phase>

<goals>

<goal>instrument</goal>

<goal>check</goal>

</goals>

</execution>

</executions>

</plugin>

4.  Running the Maven project for analysing the code through Sonar.

     (a) Run Sonar on the maven project

          mvn clean install sonar:sonar

     (b) Once the build is succesfull, login to sonar admin page to see the violations. Below is a snippet for the same:

 

5. Configuring Sonar Eclipse

    (a) Link projects to Sonar Eclipse

          This linkage operation can be done by right-clicking on the the project into the “Package explorer”, and then by choosing “Configure ->   Associate with Sonar…”

     

You are now all done with configuration and can start using Sonar Eclipse. Change your eclipse perspective to “Sonar”.

Advertisements

13 thoughts on “Configuring Sonar In Your Window’s Desktop

  1. Pingback: Sonar analysis for a non-maven based project « sanjitmohanty

    • I wrote it 3 yrs back. Unfortunately, I don’t have the code base with me now. It was a simple java project, nothing special. You could try setting up, by following the steps in the post, with your own project and if you face any issues, do comment here and I’ll try to help you out.

      Like

  2. while installation am getting below issue

    C:\sonarqube-5.0.1\bin\windows-x86-64>startsonar.bat
    wrapper | –> Wrapper Started as Console
    wrapper | Launching a JVM…
    jvm 1 | Wrapper (Version 3.2.3) http://wrapper.tanukisoftware.org
    jvm 1 | Copyright 1999-2006 Tanuki Software, Inc. All Rights Reserved.
    jvm 1 |
    jvm 1 | 2015.04.02 19:49:39 INFO app[o.s.p.m.JavaProcessLauncher] Launch pro
    cess[search]: C:\Program Files\Java\jre6\bin\java -Djava.awt.headless=true -Xmx1
    G -Xms256m -Xss256k -Djava.net.preferIPv4Stack=true -XX:+UseParNewGC -XX:+UseCon
    cMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupanc
    yOnly -XX:+HeapDumpOnOutOfMemoryError -Djava.io.tmpdir=C:\sonarqube-5.0.1\temp –
    cp ./lib/common/*;./lib/search/* org.sonar.search.SearchServer C:\Users\ABDULR~1
    .PIT\AppData\Local\Temp\1\sq-process9188280015419045139properties
    wrapper | <– Wrapper Stopped

    Please Help me

    Like

    • Hi Abdul, you should look at the “sonar.log” file located under the “logs” sonar installation directory. It should show you the cause of the startup failure. If not, then I would suggest you to increase the logging level to “DEBUG” for “wrapper.logfile.loglevel” key in “wrapper.conf” file located under the “conf” sonar installation directory and then restart sonar. Check the “sonar.log” file. Hope it helps!

      Like

  3. Hi Sanjit,
    Eclipse asking username & password, while installing sonar plugin from eclipse. I have given as admin/admin, but same is not accepted. Please suggest.

    Like

    • Hi Chandra,
      Are you trying to install the plugin behind firewall? I mean like from your office network? If so, then you need to configure network settings in your eclipse preference & provide your network username & password there. Only then your plugin should get installed.

      Do let me know if that is not the case?

      _Sanjit

      Like

      • HI Sanjit, Tried from my personal internet connection also, eclipse asking username & password for “http://dist.sonar-ide.codehaus.org/eclipse/”

        Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s