Sonar Eclipse

转载 2012年03月31日 16:04:05
Sonar Eclipse provides a comprehensive Sonar integration for Eclipse. The objective of this Eclipse plugin is that developers do not have to leave their favorite IDE to get valuable information on code quality. Most of the information displayed in the Sonar Web interface is now available in Eclipse.

Installing Sonar Eclipse is pretty simple. For instructions, prerequisites and a demonstration video go to Installing Sonar Eclipse.


  • Get quality measures on resource (project, package and files)
  • Get hotspots on given metrics (files with most duplicated lines, most complex files...)
  • Displays markers on source code upon violation of a coding standard
  • Get comprehensive list of violations on a resource
  • Bridge to Sonar Web server for access additional services (clouds, treemap...)
  • Remote or local mode
  • Track reviews assigned to the current user

Configure Sonar Eclipse

Sonar Eclipse is pre-configured to access local Sonar server listening on http://localhost:9000/. To use an other address, you need first to define this server by using the Eclipse global Preferences window :

Link projects to Sonar server

Once Sonar server is defined, the next step is to "link" eclipse projects with projects defined and analysed in Sonar server(s). 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.

In some cases the eclipse project may not be automatically associated to a Sonar project. If that happens, you need to manually enter the groupId and the artifactId of the Sonar project.
For instance for the following Sonar project, the groupId is "org.codehaus.sonar-plugins" and the artifactId is "sonar-flex-plugin".

Unlink a project from Sonar server

This operation can be done by right-clicking on the the project into the "Package explorer", and then by choosing "Configure -> Remove Sonar Nature" :

Use Sonar Eclipse

Sonar Eclipse provides one eclipse perspective and four eclipse views. Those eclipse views can of course be used outside the "Sonar" eclipse perspective, but this tutorial describes the default "Sonar" eclipse perspective layout.

To activate the "Sonar" eclipse perspective, click on "Windows -> Open Perspective -> Other ..." and select "Sonar" :

Measures view

The Measures view allows to gather all available measures on the selected ressource. Most of the time, developers focus their attention on only a few metrics like complexity, uncovered lines of code by unit tests, duplicated lines, ... and want to get a quick overview on those metrics. That's why favourite metrics are displayed on the top of the Measures view. Adding or Removing a metric from the favourites list is possible by right clicking on the metric name :

Violations view

The Violations view displays the list of violations to quality rules for the selected ressource :

A double-click on a violation opens the source code editor and highlights the violation :

Once a violation has been fixed, you can simply delete it by clicking on the violation icon and then by selecting the "Delete violation" item. Deleting a violation also removes it from the Violations view :

Hotspots view

The Hotspots view allows to quickly identify hotspots on files according to favourite metrics (defined in the Measures view). You can for instance look at files with the greatest number of duplicated lines, greatest number of violations, greatest number of uncovered lines by unit tests...

Web view

The Web view displays the web Sonar dashboard (for projects and packages) or the web Sonar ressource viewer (for files). This web page can be used to access information and services (cloud, treemap, ...) that are not yet natively available in Sonar Eclipse :

Local analysis

By default Sonar Eclipse takes care to automatically collect information from the Sonar Web server and decorates the source code on-the-fly. This default behavior is pretty useful as it doesn't consume any CPU or memory on the developer's computer while quickly displaying valuable quality information as soon as a new source file is opened. But if lot of source code is modified locally, quality information available remotely might be desynchronized after a while. In that case, a local quality analysis can be run before committing any chances to the source code repository and with the same quality profile used to analyse the project remotely.

Switching from the remote to the local mode can be done by right-clicking on the the project into the "Package explorer", and then by choosing "Configure -> Sonar -> Analyse -> Locally". As soon as this mode is selected a local analysis is launched to update Violations and Measures views.

Later, at any time, you can run a new local analysis by choosing "Configure -> Sonar -> Run Local Analysis.

Be Careful

Even in local mode, the Hotspots and Web views still display remote data.


Feature available since Sonar Eclipse 2.1

A Sonar Mylyn connector allows to track all open reviews assigned to the current user. To start using this feature, a new Sonar task repository and a query to get all reviews assigned to the current user must be first created (see theMylyn documentation page) :

Then the "Task List" view must be used to start working on all those assigned reviews :

From there, double clicking on a review open the detail of that review :

All operations on reviews available through the Sonar web interface are also available in Mylyn, so a review can be commented, fixed, reassigned, flagged as false-positive and reopened. Moreover a review can be created directly from the Eclipse source code editor on an existing violation :
This Mylyn extension has currently the following limitations that should be quickly fixed

  • There is no way to create a review that doesn't relate to an existing violation
  • There is no way to create a Mylyn query with filters in order for instance to retrieve reviews only on a project, or reviews assigned to another user



  • 2013年07月30日 14:59
  • 1.12MB
  • 下载


  • 2012年08月20日 07:49
  • 30.65MB
  • 下载


  • limm33
  • limm33
  • 2016年04月18日 16:48
  • 3346

sonar eclipse插件sonarlint

  • 2015年11月16日 13:59
  • 351KB
  • 下载


这里前提是已经安装了sonar的server端服务器。 这个eclipse的sonar客户端就是为了我们直接快速将sonar分析出的java相关bug以及警告定位到具体代码行 1.1 so...
  • kongqz
  • kongqz
  • 2013年05月08日 16:49
  • 4340


Sonar通过插件的形式与Eclipse集成,可以实现实时代码质量分析,前提条件是sonar服务器已经正常工作。 一、启动eclipse,下载并安装sonar插件 安装完成...
  • jamenew
  • jamenew
  • 2017年02月04日 17:23
  • 1345

Maven中sonar的配置与eclipse sonar插件的安装

安装好sonar后,跑sonar有三种方式  1. 通过maven插件跑,这个很简单,只需要简单的修改maven的settings文件就好了,在下面增加 sonar tru...
  • ynwso
  • ynwso
  • 2013年03月26日 17:58
  • 7227


  • 2017年10月25日 17:50
  • 173KB
  • 下载


  • 2017年09月20日 15:58
  • 9.63MB
  • 下载


上一次是通过修改sonar管理系统的标识 最近发现一个更好的方法,就是在增加“branch”参数。 在SonarQube analysis with Maven中增加branch(分支),对当前的so...
您举报文章:Sonar Eclipse