SonarQube集成到Eclipse中

1、在Eclipse中安装SonarQube插件

Go to Help > Eclipse Marketplace... and search for "SonarQube"
or
Go to Help > Install New Software... This should display the Install dialog box. Paste the Update Site URL (http://dist.sonar-ide.codehaus.org/eclipse/ the latest version or http://dist.sonar-ide.codehaus.org/eclipse-archives/ for previous ones) into the field Work with and press Enter. This should display the list of available plugins and components:

140314_fYdR_870039.jpg

安装成功后

2、在Eclipse中配置SonarQube

1)、在项目根目录底下,配置sonar-project.properties文件

# Required metadata
sonar.projectKey=nutch-key
sonar.projectName=nutch-prj
sonar.projectVersion=1.0
# Path to the parent source code directory.
# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
# Since SonarQube 4.2, this property is optional. If not set, SonarQube starts looking for source code
# from the directory containing the sonar-project.properties file.
sonar.sources=src
# Encoding of the source code
sonar.sourceEncoding=UTF-8
# Additional parameters
sonar.my.property=value

注意:

sonar.projectKey、sonar.projectName这两个属性的值,应当根据Sonar Web中我们指定的值而定。

如果是第一次在Eclipse中分析项目,并且没有直接用sonar-runner命令分析过项目。

我们需要在Sonar Web中做关于sonar.projectKey、sonar.projectName的一些配置,配置情况如图所示:

143007_wbn5_870039.jpg143758_4wik_870039.jpg

创建key和project成功后,我们进行下面的配置:

2)、Go to Window > Preferences > SonarQube > Servers.

141304_YtRE_870039.jpg

3)、Configure -> Associate with SonarQube

144034_bKAk_870039.jpg

144341_68Sc_870039.jpg

4)、配置完成后,sonar-runner开始运行,但是,我们会发现,控制台报错,出现错误信息为:

Project not found on remote SonarQube server [nutch-key]

5)、单击右键选择SonarQube -> Change Project Association,我们会发现,之前我们配置的SonarQube Project,并未配置成功。

144851_lJbT_870039.jpg

3、配置失败后解决方案

出现上述失败后,我们需要首先通过 《用SonarRunner命令分析Java项目》这篇文章中的方法分析项目成功后,才能在Eclipse中使用插件成功。

在项目所在目录下运行sonar-runner命令

E:\qjay\wrokespace2013\nutch-solr-filter>sonar-runner -e
成功后,我们可以访问http://localhost:9000查看分析结果

4、在第3步成功后,我们再重新做第2步中的第5)小步

在Sonar Project中添加nutch-prj,此时我们会发现可以添加成功(因为现在nutch-prj才真实的存在了)。

5、添加成功后,点击SonarQube -> Analyze,分析项目,现在可以分析成功了

我们可以单击右键选择SonarQube -> Open in SonarQube Server,在Eclipse中查看分析结果。

150412_3yoL_870039.jpg

感悟:

经过Eclipse中安装SonarRunner插件,给我的感觉是,没太大实际意义。

不知道是我在Eclipse中配置插件的方法不对还是怎么了,为什么非要在控制台使用命令分析项目成功后,才能在Eclipse中正确连接Sonar Web,并且才能正确分析项目呢?

既然我们在控制台利用命令就能分析成功,那么我们还需要在Eclipse中安装SonarQube插件干什么呢?

所以,我觉得其实在Eclipse中安装SonarQube插件分析项目的意义不是太大。



转载于:https://my.oschina.net/HIJAY/blog/294875

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值