惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
Visual Studio Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
N
Netflix TechBlog - Medium
博客园 - 叶小钗
大猫的无限游戏
大猫的无限游戏
S
SegmentFault 最新的问题
V
V2EX
IT之家
IT之家
J
Java Code Geeks
Hacker News - Newest:
Hacker News - Newest: "LLM"
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
GbyAI
GbyAI
D
Docker
S
Secure Thoughts
Recent Announcements
Recent Announcements
Webroot Blog
Webroot Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
云风的 BLOG
云风的 BLOG
博客园_首页
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Security Archives - TechRepublic
Security Archives - TechRepublic
酷 壳 – CoolShell
酷 壳 – CoolShell
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
N
News | PayPal Newsroom
S
Security @ Cisco Blogs
I
InfoQ
Last Week in AI
Last Week in AI
SecWiki News
SecWiki News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
W
WeLiveSecurity
T
Troy Hunt's Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Attack and Defense Labs
Attack and Defense Labs
美团技术团队
T
The Blog of Author Tim Ferriss
Google DeepMind News
Google DeepMind News
Martin Fowler
Martin Fowler
B
Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Scott Helme
Scott Helme
T
Tor Project blog
Know Your Adversary
Know Your Adversary
有赞技术团队
有赞技术团队
Hugging Face - Blog
Hugging Face - Blog
Recorded Future
Recorded Future
C
Cyber Attacks, Cyber Crime and Cyber Security
AI
AI
G
Google Developers Blog

CAYZLH

英雄联盟的昨日今天与符文大乱斗 折腾的尽头是极简 MacBook上备忘录APP的快捷键和手势 让Google屏蔽某些搜索结果 WSL自定义安装Ubuntu typora自动上传图片配置 自建giscus服务 Windows下结束指定端口的进程 批量修改maven多模块版本号 使用winsw部署SpringBoot项目 Gson简易指南 docker搭建Consul集群 使用Docker部署SpringBoot项目 Docker使用redis镜像 Docker使用rabbitmq Docker使用zookeeper Docker使用MySQL Dockerfile常用指令 Docker免sudo操作 雷鸟电视去广告 使用ADB卸载MIUI系统应用 利用GitHub做图床 将网站变成灰色 Github上传大文件 Android远程调试命令adb vscode快捷键的使用 SpringBoot文件上传异常处理 SpringBoot封装JedisUtils工具类 SpringBoot自动部署脚本 使用Spring读取文件的几种方式 Spring统一异常返回 利用Github做Maven私服 Redis常用指令 Maven常用指令 使用mysqldump导出数据 SpringBoot动态切换多数据源 Java8的日期处理实践 lambda表达式语法 Stream表达式语法 使用Optional优雅地判空 Android Support vs AndroidX 「Vue」Runtime-Complier和Runtime-only的区别 RecyclerView使用记录 动态设置布局之LayoutInflater Redis分布式锁的几种方案 打造一个舒服的写作环境(Hexo) 深入了解与使用ThreadLocal Maven中dependencyManagement的作用 Redis配置认证密码 nginx简单配置示例 Linux(macOS)换源 Linux搭建Git服务器 Linux配置ssh使用公钥登录远程服务器 Linux下find与exec的使用 Linux排查Java问题工具单 Linux常用命令 MySql数据库优化细节 API签名验证方案 Java集合框架 Redis基础知识总结 Spring事务管理 Redis为什么这么快 SpringBoot实现Jwt单点登录 SpringBoot实现Redis分布式锁 Spring面向切面编程(知识梳理) SpringBoot异步请求和异步调用 Mybatis中用到的几种设计模式 Docker Swarm RocketMQ相关流程图/原理图 宝塔面板部署vue项目 Tomcat的三种接收请求处理方式 Docker知识扫盲 安装Jenkins并用于部署SpringBoot项目 Tomcat单机多实例部署 Maven中Scope的分类 Springboot集成Shiro(前后端分离) Linux搭建frp服务(内网穿透) Redis高逼格指令 Docker私有仓库的搭建与使用 Dockerfile使用介绍 Redis的使用场景 Docker的网络模式
SonarQube的安装与使用
Ant丶 · 2019-08-27 · via CAYZLH

前言

随着代码量的越来越多,同时对代码质量的要求也越来越高,对于代码review的需求越来越多。因此,引入SonarQube这个工具对Java代码进行质量管控。

SonarQube(曾用名Sonar(声纳))是一个开源代码质量管理系统。

安装

前置条件

  • 系统环境:Centos 7
  • Java环境:1.8
  • SonarQube版本:6.7.7

由于最新版的SonarQube7.9要求Java环境必须是Java11以上,我们目前开发使用的是1.8,所以选用较低版本的6.7.7

创建sonar用户

由于sonar用到了es,不允许直接使用root用户运行,因此,需要在linux下,创建sonar用户,专门用来运行sonar程序。

假设当前使用的是root用户登录:

useradd sonar
passwd sonar
su sonar

安装mysql数据库,创建sonar库

1、mysql的安装步骤:记录Linux安装Mysql全过程

2、创建sonar库

​ 创建sonar数据库,用于保存soanrqube的扫描数据

安装sonarqube

1、将sonar6.7.7安装包拉到/opt/SonarQube目录

2、解压

unzip sonarqube-6.7.7.zip

3、修改配置

vi ./sonarqube-6.7.7/conf/sonar.properties

添加mysql配置:







sonar.jdbc.username=sonar
sonar.jdbc.password=*******




sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance&useSSL=false

省略了不需要展示的部分

创建软连接

ln -s /opt/SonarQube/sonarqube-6.7.7/bin/linux-x86-64/sonar.sh /usr/bin/sonar

运行sonar

sonar start

重启 sonar restart

停止 sonar stop

查看状态 sonar status

可能遇到的问题

  • 没有目录权限:

    将目录授权给sonar用户:

    su root
    chown -R sonar /opt/SonarQube
  • 没有操作权限

    chmod a+x /opt/SonarQube/sonarqube-6.7.7/bin/linux-x86-64/sonar.sh
    chmod a+x /opt/SonarQube/sonarqube-6.7.7/bin/linux-x86-64/wrapper
    chmod a+x /opt/SonarQube/sonarqube-6.7.7/elasticsearch/bin/elasticsearch
  • 数据库问题

    录数据库后执行:

    SET GLOBAL max_allowed_packet = 4*1024*1024*16

使用

Java

扫描Java的maven项目,首先要在pom.xml中添加配置:

<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.3.0.603</version>
</plugin>

使用logintoken扫描

mvn sonar:sonar \
-Dsonar.host.url=http://10.0.2.91:9000 \
-Dsonar.login=youtoken

其中youtoken可以在登录sonar后台后找到:我的账号 - 安全

token

设置settings.xml扫描

修改本地maven的settings.xml文件,添加配置:

<pluginGroups>
<pluginGroup>org.sonarsource.scanner.maven</pluginGroup>
</pluginGroups>

<profiles>
<profile>
<id>sonar</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>

<sonar.host.url>
http://10.0.2.91:9000
</sonar.host.url>
</properties>
</profile>
</profiles>

然后执行:

mvn clean verify sonar:sonar

mvn clean install sonar:sonar

mvn clean -Dmaven.test.skip=true verify sonar:sonar

或在IDEA中执行maven插件:

idea sonar plugin

分析

扫描完成后,登录sonar后台,将可以看到本次扫描的项目,和相应的分析:

sonar

over

^_^.

参考