sonarqube+maven实现代码质量检测

sonarqube+maven实现代码质量检测

一、安装sonarqube

  1. 下载安装包 https://www.sonarqube.org/ 注:7.9以上版本不支持mysql
  2. 下载后目录,bin下是各个系统启动方式,如Windows-bat,Linux-sh。conf目录下为sonar配置文件。
    在这里插入图片描述

二、配置sonarqube

编辑conf目录下sonar.properties

// 需要为sonar准备一个数据库,也可以更改默认端口  #sonar.web.port=9000
sonar.jdbc.username=root
sonar.jdbc.password=123456
sonar.jdbc.url=jdbc:mysql://xxx/sonar?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&&useSSL=false&&allowMultiQueries=true

三、启动环境配置

  1. ES不能再root账号下启动,要创建一个用户
#新增用户
$ adduser sonar
#配置密码
$ passwd sonarUser
#配置路径权限
$ chown -R sonarUser:sonarUser sonarqube-6.7.2
  1. 启动时报错及解决方式(bin目录下启动)
[1]: max number of threads [1024] for user [hadoop] is too low, increase to at least [2048]
[2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
[3]: system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk

vim /etc/security/limits.conf
* soft nproc 65536
* hard nproc 65536
* soft nofile 65536
* hard nofile 65536

vim /etc/security/limits.d/90-nproc.conf 
soft nproc 2048

vi /etc/sysctl.conf
vm.max_map_count=262144

sysctl -p

vim elasticsearch.yml
bootstrap.memory_lock: false
bootstrap.system_call_filter: false

四、maven配置

主要配置sonar服务地址

  <profile>
      <id>sonar</id>
      <activation>
          <activeByDefault>true</activeByDefault>
      </activation>
    <properties>
       <sonar.host.url>http://localhost:9000</sonar.host.url>
    </properties>
  </profile>
  
<activeProfile>sonar</activeProfile>

五、集成jacoco生成报告

生成报告,路径在target下,index.html为网页的报告内容
mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent install -Dmaven.test.failure.ignore=true

<plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.8.3</version>
                <executions>
                    <execution>
                        <id>prepare-agent</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>report</id>
                        <phase>test</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

六、生成sonar报告
mvn sonar:sonar -Dsonar.projectKey=com.funtl:itoken-uaa -Dsonar.host.url=http://localhost:9000 -Dsonar.login=token
根据自己的项目配置改动
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值