SonarQube是管理代码质量一个开放平台,可以快速的定位代码中潜在的或者明显的错误,下面将会介绍一下这个工具的安装、配置以及使用。
一。准备工作;
1、jdk(不再介绍)
2、sonarqube:http://www.sonarqube.org/downloads/
3、SonarQube+Scanner:https://sonarsource.bintray.com/Distribution/sonar-scanner-cli/sonar-scanner-2.5.zip
4、mysql数据库(不再介绍)
二.版本说明
sonar 的版本5.4,
sonar-scaner的版本是2.5
经测试不支持7.3
三.配制
sonarqube解压后,配制sonar.properties
sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance sonar.jdbc.username=root sonar.jdbc.password=root sonar.sorceEncoding=UTF-8 sonar.login=admin sonar.password=admin # By default, ports will be used on all IP addresses associated with the server. sonar.web.host=localhost # Web context. When set, it must start with forward slash (for example /sonarqube). # The default value is root context (empty value). sonar.web.context=/sonar # TCP port for incoming HTTP connections. Disabled when value is -1. sonar.web.port=9000
创建DB:sonar
配制sonar-scanner-2.5
#----- 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=admin sonar.jdbc.password=admin #----- PostgreSQL #sonar.jdbc.url=jdbc:postgresql://localhost/sonar #----- MySQL #sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8 sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance sonar.jdbc.username=root sonar.jdbc.password=root
配制:sonar-project.properties 此文件放入项目根目录中
sonar.projectKey=springboot003 sonar.projectName=springboot003 sonar.projectVersion=1.0 sonar.sources=src #sonar.tests=tests sonar.language=java sonar.sourceEncoding=UTF-8
四.启动:
1.先启动服务,初次启动很慢,需要点时间
启动完成后会创建DB,并初始化,然后会出一个问题,好像只有5.4版本会有,
需要执行:
http://localhost:9000/setup.
下载中文JAR包。sonar-l10n-zh-plugin-1.9.jar
放入:sonarqube-5.4extensionsplugins
重启服务即可
2.再启动客户端
客户端 启动还需要配一下环境变量:
SONAR_RUNNER_HOME=D:JavaEEServersonar-scanner-2.5
path中加入:%SONAR_RUNNER_HOME%in;
然后进入项目根目录执行:sonar-runner -X
五。结果