栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

sonarQube(代码扫描工具)安装配置

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

sonarQube(代码扫描工具)安装配置

sonarqube使用介绍@[TOC]sonarqube使用介绍

sonarQube使用介绍

本文不讲解 什么是sonarQube,请自行了解 sonarQube安装

sonarQube分为2个 部分

    sonarQube 展示扫描结果;sonarScanner 扫描工具;
环境

jdk11+;sonarQube的运行需要 安装包下载

    sonarQube官网地址 : https://www.sonarqube.org/downloads/sonar-scanner官网地址:https://docs.sonarqube.org/latest/analysis/scan/sonarscanner/注意选择sonar-scanner的版本选择需要根据sonarQube决定,
    数据库包,推荐使用PostgreSQL:官网地址:https://www.enterprisedb.com/downloads/postgres-postgresql-downloads,(源码地址)https://www.postgresql.org/ftp/source/,如果环境是linux环境且有网络,可直接使用yum安装
    sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
    sudo yum install -y postgresql14-server
    sudo /usr/pgsql-14/bin/postgresql-14-setup initdb
    sudo systemctl enable postgresql-14
    sudo systemctl start postgresql-14
安装
    sonarQube和sonarScanner都是免安装的,直接解压即可,同时将sonarScanner加入环境变量(bin目录路径,方便调用)数据库postgresql ,如果是windows的这直接安装,全选默认,若为linux yum安装,直接安装(见安装包下载4数据库包)
环境配置
    sonarQube关联数据库
    window: https://www.cnblogs.com/Simple-Small/p/12882948.html
    linux:
    安装完后会自动创建postgres用户 su - postgres切换进去
    psql 进入命令行模式
    create database sonar; 创建sonar数据库
    create user sonar; 创建sonar用户
    atler user sonar with password ‘postgres’; 设置sonar用户密码(否则会导致连不上数据库)
    alter role sonar createdb;alter role sonar superuser;alter role sonar createrole;给sonar授权
    alter database sonar owner to sonar;更改sonar数据库拥有者(这一步是必须的,否则会sonarqube会连接失败)
    原文链接:https://blog.csdn.net/qq_42207325/article/details/100998453启动sonarQube,进入下面目录,根据当前系统选择相应的目录直接运行

    linux:直接运行下面脚本sh sonar.sh (选项:start、stop、status、console起不来用这个看看)

    windows:

    启动后网页打开http://localhost:9000/ 进入sonarQube 的web界面,默认用户密码:adminadminsonarScanner关联sonarQube,修改sonarScanner目录下的文件,后2项为sonarQube 的web界面的登录
C++、C支持

sonarQube 社区版不支持c++、c代码扫描,需要用到其他的扫描工具cppcheck
下载地址:https://cppcheck.sourceforge.io/
安装后加入环境变量(bin目录路径,),方便调用
linux :可直接使用yum 安装

sonarQube 安装c++报告解析插件:https://github.com/SonarOpenCommunity/sonar-cxx/releases
将插件放到sonarqube-8.9.6.50800extensionsplugins 目录下,重启sonarQube

项目扫描

带c++c的项目,需要先扫描C++C 使用前面安装的cppcheck工具,命令为:
cppcheck --xml --xml-version=2 --enable=all ./ 2> cppcheck-report.xml

扫描完成后,在项目所在根目录配置一下文件和内容:例

下面2项将在sonarQube Web界面显示为该项目的名称

sonar.projectKey=javasonar.projectName=java

sonar.sourceEncoding=UTF-8 :原代码的编码规则
sonar.sources=. :要扫描的目录文件
sonar.java.binaries=src:java源代码的编译文件路径
sonar.cxx.cppcheck.reportPaths=reports/cppcheck.xml:如有c++、c代码则添加,值为cppcheck扫描结果所在路径

最后在sonar-project.properties所在目录 执行sonar-scanner

待完成后就可在web界面查看扫描结果

最后,温馨提示:sonarQube 扫描结果的指标意义请查看官方文档:https://docs.sonarqube.org/8.9/user-guide/metric-definitions/

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/752447.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号