您的位置:首页 > 编程语言

sonarQube代码质量管理笔记

2016-09-13 10:53 381 查看
jdk 版本 1.7 

linux 32位

我用的 sonar的版本是: sonarqube-5.1.2  和 sonar-runner-2.4   因为版本问题各种报错 (sonar 和jdk版本不符,run和sonar版本不符,svn版本过低 等等等等) 安装的时候 也是心累

1数据库配置 

sonar会往数据库里头创很多很多表 实现各种业务 所以首先建表建用户

<span style="white-space:pre">	</span>CREATE DATABASE sonar CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE USER 'sonar' IDENTIFIED BY 'sonar';
GRANT ALL ON sonar.* TO 'sonar'@'%' IDENTIFIED BY 'sonar';
GRANT ALL ON sonar.* TO 'sonar'@'localhost' IDENTIFIED BY 'sonar';
FLUSH PRIVILEGES;


2修改sonar配置文件

文件 sonar.properties

<span style="white-space:pre">	</span>sonar.jdbc.username=sonar
sonar.jdbc.password=sonar
sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformances
sonar.jdbc.driverClassName=com.mysql.jdbc.Driver
sonar.web.host=192.168.1.108 -- 本机ip 127.0.0.1应该也是可以的
sonar.web.context=/   --项目名称  也可以这样 /sonar  /lajidaima
sonar.web.port=4506 --我的9000端口让狗吃了


文件 wrapper.conf

加一条 

<span style="white-space:pre">	</span>wrapper.java.command=/usr/lib/jvm/java-7-openjdk-i386/bin/java  --jdk路径自己找


3启动sonar

命令

<span style="white-space:pre">	</span>/usr/local/sonarqube-5.1.2/bin/linux-x86-32/sonar.sh start
/usr/local/sonarqube-5.1.2/bin/linux-x86-32/sonar.sh stop
/usr/local/sonarqube-5.1.2/bin/linux-x86-32/sonar.sh restart

如此就成功启动了

4对代码进行质量管理 

这里用 sonar-runner

配置sonar-runner

sonar.host.url=http://192.168.1.108:4506
sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance
sonar.jdbc.username=sonar
sonar.jdbc.password=sonar
sonar.sourceEncoding=UTF-8


在项目目录下创建文件sonar-project.properties

</pre><pre>

# required metadata
sonar.projectKey=education-manager-web
sonar.projectName=manager
sonar.projectVersion=1.0

# path to source directories (required)
sonar.sources=/root/.jenkins/workspace/education-manager-web/src

# path to test source directories (optional)不懂
#sonar.tests=testDir1,testDir2

# path to project binaries (optional), for example directory of Java bytecode
#sonar.binaries=binDir

# optional comma-separated list of paths to libraries. Only path to JAR file and path to directory of classes are supported.
sonar.libraries=target/classes,/root/.m2/repository

# Uncomment this line to analyse a project which is not a java project.
# The value of the property must be the key of the language.
sonar.language=java

# Additional parameters
#sonar.my.property=value

sonar.sourceEncoding=UTF-8

执行sonar-runner命令

先cd 到sonar-project.properties这个文件所在目录  然后执行

/usr/local/sonar-runner-2.4/bin/sonar-runner -e    -e是显示详细log日志


和jenkins整合 

新建一个项目用来执行shell命令  在指定项目重新构建后执行该项目 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  sonarqube