Sonar配置与使用
一、前置条件:
安装工具如下:
- JDK
- MySql服务器
- SonarQube
- SonarScanner
从官网下载安装包进行安装,具体安装步骤略
二、配置
MySql配置:
打开SQL,创建sonar数据库,sonar用户,并赋予sonar用户sonar数据库权限;
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;
Ps:mysql8.0以上版本配置如下
CREATE DATABASE sonar CHARACTER SET utf8 COLLATE utf8_general_ci;
delete from mysql.user where user='sonar'; //如果存在sonar用户,先删除再创建,无sonar用户,略过此步
CREATE USER 'sonar'@'localhost' IDENTIFIED BY 'sonar';
CREATE USER 'sonar'@'%' IDENTIFIED BY 'sonar';
GRANT ALL ON sonar.* TO 'sonar'@'%';
GRANT ALL PRIVILEGES ON sonar.* TO 'sonar'@'localhost';
flush privileges;
Sonar、SonarScanner环境变量配置:
添加SONAR_HOME、SONAR_RUNNER_HOME环境变量,并将SONAR_RUNNER_HOME加入PATH
修改sonar配置文件sonar.properties
# User credentials.
# Permissions to create tables, indices and triggers must be granted to JDBC user.
# The schema must be created first.
sonar.jdbc.username=sonar
sonar.jdbc.password=sonar #----- Embedded Database (default)
# H2 embedded database server listening port, defaults to 9092
#sonar.embeddedDatabase.port=9092
#----- MySQL 5.6 or greater
# Only InnoDB storage engine is supported (not myISAM).
# Only the bundled driver is supported. It can not be changed.
sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance&useSSL=true
#Optional properties
sonar.jdbc.driverClassName=com.mysql.jdbc.Driver
修改SonarScanne配置文件sonar-scanner.properties
#----- Default SonarQube server
sonar.host.url=http://localhost:9000 #----- Default source code encoding
sonar.sourceEncoding=UTF-8 #----- Global database settings (not used for SonarQube 5.2+)
sonar.jdbc.username=sonar
sonar.jdbc.password=sonar #----- PostgreSQL
#sonar.jdbc.url=jdbc:postgresql://localhost/sonar #----- MySQL
sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8 #----- Oracle
#sonar.jdbc.url=jdbc:oracle:thin:@localhost/XE #----- Microsoft SQLServer
#sonar.jdbc.url=jdbc:jtds:sqlserver://localhost/sonar;SelectMethod=Cursor
#----Security(when 'sonar.forceAuthentication'is set to 'true')
sonar.login=admin
sonar.password=admin
三、启动
进入sonar的bin目录找到sonar启动文件,启动sonar服务
输入localhost:9000访问,页面展示如图
三、使用
通过maven进行集成
修改maven配置文件setting.xml
<?xml version="1.0" encoding="UTF-8"?> <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"> <localRepository>D:/repository</localRepository> <pluginGroups> <pluginGroup>org.sonarsource.scanner.maven</pluginGroup>
</pluginGroups> <proxies> </proxies>
<servers> <id>siteServer</id>
<privateKey>/path/to/private/key</privateKey>
<passphrase>optional; leave empty if not used.</passphrase>
</server>
-->
<server>
<id>releases</id>
<username>admin</username>
<password>admin123</password>
</server> </servers> <mirrors>
<mirror>
<id>nexus</id>
<name>nexus Mirror,3rd party,chenshu repository</name>
<url>http://192.168.102.92:8081/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors> <profiles>
<profile>
<id>jdk1.8</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>1.8</jdk>
</activation>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
</properties>
<repositories>
<repository>
<id>snapshots</id>
<url>http://192.168.102.92:8081/nexus/content/repositories/snapshots/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
</profile>
<profile>
<id>sonar</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<!-- Optional URL to server. Default value is http://localhost:9000 -->
<sonar.jdbc.url>jdbc:mysql://localhost:3306/sonar</sonar.jdbc.url>
<sonar.jdbc.driver>com.mysql.jdbc.Driver</sonar.jdbc.driver>
<sonar.jdbc.username>sonar</sonar.jdbc.username>
<sonar.jdbc.password>sonar</sonar.jdbc.password>
<sonar.host.url>http://localhost:9000</sonar.host.url>
</properties>
</profile>
</profiles>
<activeProfiles>
<activeProfile>sonar</activeProfile>
</activeProfiles> </settings>
然后把配置文件copy至C:\Users\Administrator\.m2目录
进入项目pom文件所在目录,地址栏输入cmd,进入命令窗口
执行mvn sonar:sonar
执行成功会把分析结果保存至数据库,通过浏览sonar地址访问
Sonar配置与使用的更多相关文章
- 代码质量管理工具 sonar 配置
代码检查工具有很多findBugs等等 sonar配置: 1.下载sonar 5.5, 解压,运行 sonarqube-5.5\bin\windows-x86-64\StartSonar.bat , ...
- Sonar 配置及部署(Linux系统)
之前在windows系统上部署了sonar代码审查,由于工作需要,需要在Linux环境再部署一套. 其实,部署的大体都是大同小异的,这里罗列下各个配置,与windows部署不同的地方会重点说一下. 数 ...
- Sonar 配置及部署(windows系统)
Sonar 是一个用于代码质量管理的开放平台.通过插件机制,Sonar 可以集成不同的测试工具,代码分析工具,以及持续集成工具. 与持续集成工具(例如 Hudson/Jenkins 等)不同,Sona ...
- jenkins + sonar 安装配置
最近把snoar 添加上了 [root@snoar data]# wget https://sonarsource.bintray.com/Distribution/sonarqube/sonar ...
- Jenkins集成Sonar Quabe和权限配置
目录 安装Sonar Jenkins配置sonar Maven Jenkins Job配置 Pipeline Jenkins Job配置 Sonar权限管理 Sonar quality Gate通过阈 ...
- pipeline配置sonar和自动化
1.sonar配置webhooks, 2.url填写jenkins的地址:http://jenkinsurl/sonarqube-webhook/ 3.前提:jenkins配置好sonar的scann ...
- iOS Sonar 集成流程
https://gold.xitu.io/entry/5781e6872e958a0054c93368 作者:advancer_chen,原文链接:http://my.oschina.net/Chen ...
- Sonar入门(五):使用 Sonar 进行代码质量管理
Sonar 概述 Sonar 是一个用于代码质量管理的开放平台.通过插件机制,Sonar 可以集成不同的测试工具,代码分析工具,以及持续集成工具. 与持续集成工具(例如 Hudson/Jenkins ...
- sonar + jacoco + mockMvc 模拟session 用户登录 配合SpringSecurity 权限 快速测试代码覆盖率.
遇到mock 测试简直就是神器,特别是要做代码覆盖率,直接测试controller就好了,缺点,虽然可以回滚事务,但是依赖数据库数据,解决,根据SpringBoot ,再建立一个专门跑单元测试的数据库 ...
随机推荐
- [PHP]PHPOffice/PHPExcel数据导入方法
------------------------------------------------------------------------------------ /** * PHPExcel数 ...
- 吴裕雄 17-MySQL 排序
如果我们需要对读取的数据进行排序,我们就可以使用 MySQL 的 ORDER BY 子句来设定你想按哪个字段哪种方式来进行排序,再返回搜索结果. 以下是 SQL SELECT 语句使用 ORDER B ...
- 学JS的心路历程-闭包closure
闭包是是纯函式语言的一个特性,也是JS的一个关键性的特色,虽然不了解也能开发程序,但我们不是这种人对吧? 闭包不仅可以减少某些高阶功能的代码数量和复杂度,并且可以让我们做到原本无法做的复杂功能.听到这 ...
- 学习JS的心路历程-参数传递方式(上)
很多人认为JS的传递方式是值是Call by value, 物件及数组是Call by Reference.甚至还有人宣称其实JS是Call by sharing,那到底是哪一个呢? 这两天我们一一来 ...
- java的acm输入输出格式+大数语法
1.类名称必须采用public class Main方式命名 2.多组输入,读取到文件尾 Scanner scan=new Scanner(System.in); while(scan.hasNext ...
- 构建缓存gradle
结合Kotlin使用Gradle build cache 宛丘之上兮 关注 2018.03.11 00:21* 字数 1177 阅读 505评论 5喜欢 4 在2017年4月,Gradle发布了bui ...
- OpenCV批量读入(处理)
#include <windows.h> #include <iostream> #include <opencv2/opencv.hpp> using names ...
- AlertDialog 无法去掉自带的白边
项目中开始采用AlertDialog ,根据要求要显示加圆角.但是设置圆角的背景后,会存在白边. 按网上提示的设置透明的背景都不可以. 最后采用Dialog.
- Java 几种锁
自旋锁 自旋锁顾名思义,它会等待一定时间(自旋),在这期中会什么都不做就是等资源被释放,好处在于没有了内核态用户态切换的效率损失,但是如果它一直不能访问到资源的话就会一直占用cpu资源,所以它会循环一 ...
- STL::unordered_map/unordered_multimap
unordered_map: 和 unorder_set 相似,该容器内部同样根据 hash value 把键值对存放到相应的 bucket(slot)中,根据单个 key 来访问 value 的速度 ...