sonarQube代码质量管理

来源:互联网 发布:工作证在线制作软件 编辑:程序博客网 时间:2024/05/10 11:51

SonarQube is an open platform to manage code quality.

7个维度管理源码:

这里写图片描述

source code:

https://github.com/SonarSource/sonarqube

sonarQube组件:

1.One DB to store: the configuration of the SonarQube instance the quality snapshots of projects,view

2.One Web Server for users to browse quality snapshots and configure the SonarQube instance

3.One or more Analyzers to analyze projects

这里写图片描述

组件间规则

1.只能有一个web server 和 一个DB。

2.最后是3个组件安装在不同的机器上,但是允许web server 和 DB安装在同一台机器上。

3.DB和Analyzers必须在同一个局域网内,不能安装在同一台机器上。

4.所有的机器必须是时间同步的。

运行环境需求:

http://docs.sonarqube.org/display/SONAR/Requirements

1.JDK7+

2.SonarQube server运行至少需1G内存

3.Great read & write hard drive performance

安装步骤

1.下载安装包

http://www.sonarqube.org/downloads/

2.新建DB(mysql实例)

mysql> CREATE DATABASE sonar CHARACTER SET utf8 COLLATE utf8_general_ci; mysql> CREATE USER 'sonar' IDENTIFIED BY 'sonar';mysql> GRANT ALL ON sonar.* TO 'sonar'@'%' IDENTIFIED BY 'sonar';mysql> GRANT ALL ON sonar.* TO 'sonar'@'localhost' IDENTIFIED BY 'sonar';mysql> FLUSH PRIVILEGES;

3.安装web server

1.修改配置文件

/data2/sonarqube-5.1.2/conf/sonar.properties
设置DB信息

sonar.jdbc.username=sonarsonar.jdbc.password=sonarsonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatch    edStatements=true&useConfigs=maxPerformance

2.设置访问路径

sonar.web.host=10.13.1.139sonar.web.port=9100sonar.web.context=/sonar

3.启动web server

cd /data2/sonarqube-5.1.2/bin/linux-x86-64./sonar.sh start

访问:http://10.13.1.139:9100/sonar/

默认登入账号:admin/admin

中文汉化包

源码地址:https://github.com/SonarCommunity/sonar-l10n-zh/releases/tag/sonar-l10n-zh-plugin-1.8

自己已打成jar包,下载地址:
http://download.csdn.net/download/neven7/8974753

将sonar-l10n-zh-plugin-1.8.jar放到/data2/sonarqube-5.1.2/extensions/plugins目录下,重启服务
./sonar.sh restart

4.Analyzer(以maven为例)

在本地maven的$MAVEN_HOME/conf(命令行执行mvn)中settings.xml中新增DB和web server配置

<profile>        <id>sonar</id>            <activation>                <activeByDefault>true</activeByDefault>            </activation>                <properties>                    <sonar.jdbc.url>                            jdbc:mysql://10.13.1.139:3306/sonar?useUnicode=true&amp;characterEncoding=utf8                    </sonar.jdbc.url>                    <sonar.jdbc.username>sonar</sonar.jdbc.username>                    <sonar.jdbc.password>sonar</sonar.jdbc.password>                    <sonar.host.url>                        http://10.13.1.139:9100/sonar                    </sonar.host.url>                </properties>    </profile>

在maven项目路径下:

# mvn clean -Dmaven.test.skip=true install# mvn sonar:sonar...BUILD SUCCESS

刷新10.13.1.139:9091/sonar
出现该项目
这里写图片描述

安装插件

1.配置

2.系统

3.更新中心

4.Available Plugins

5.选择对应的插件,比如PMD,FindBugs

6.重启./sonar.sh restart

0 0
原创粉丝点击