SonarQube搭建:
环境 : windows, jdk1.8 ,maven
1. 官网下载SonarQube版本,我这里下载的7.2.1版本, 官网下载地址: http://www.sonarqube.org/downloads/ ,
2. 启动: sonarqube-7.2.1\bin\windows-x86-64\StartSonar.bat, 浏览器打开localhost:9000, 即可看到SonarQube Web首页
3. 下面连接mysql数据库,我这里新建了fangqian_sonar_db:
修改 sonarqube-7.2.1\conf\sonar.properties
sonar.jdbc.url=jdbc:mysql: //dev-mysql-m .a.pa.com:3306 /fangqian_sonar_db ?useUnicode= true &characterEncoding=utf8&rewriteBatchedStatements= true &useConfigs=maxPerformance&useSSL= false sonar.jdbc.username=dev sonar.jdbc.password=dev sonar.sorceEncoding=UTF-8 sonar.login=admin sonar.password=admin sonar.web.host=0.0.0.0 (可以改成允许访问的IP) sonar.web.context=/ (浏览器端口后跟的访问路径) sonar.web.port=9000 |
- 下载SonarQube Scanner for Maven插件,
官网上写的:
From maven-sonar-plugin 3.4.0.905, SonarQube < 5.6 is no longer supported. If using SonarQube instance prior to 5.6, you should use maven-sonar-plugin 3.3.0.603. From maven-sonar-plugin 3.1, Maven < 3.0 is no longer supported. If using Maven prior to 3.0, you should use maven-sonar-plugin 3.0.2. |
我们的maven的版本是3.0以上, 下载3.0.2以上版本的插件
5. 修改maven的setting.xml
添加以下节点配置:
< settings > < pluginGroups > < pluginGroup >org.sonarsource.scanner.maven</ pluginGroup > </ pluginGroups > < activeProfiles > < activeProfile >sonar</ activeProfile > </ activeProfiles > < profiles > < profile > < id >sonar</ id > < properties > < sonar.host.url >http://localhost:9000</ sonar.host.url > < sonar.jdbc.driver >com.mysql.jdbc.Driver</ sonar.jdbc.driver > < sonar.jdbc.username >dev</ sonar.jdbc.username > < sonar.jdbc.password >dev</ sonar.jdbc.password > < sonar.jdbc.url >jdbc:mysql://dev-mysql-m.a.pa.com:3306/fangqian_sonar_db</ sonar.jdbc.url > <!-- 不想扫描的包目录 --> < sonar.exclusions >src/main/java/com/odlfy/.../**/*</ sonar.exclusions > </ properties > </ profile > </ profiles > </ settings > |
- 进入想扫描的maven项目根目录, 执行maven 命令 mvn clean install sonar:sonar ,
扫描完成后, 重新打开http://localhost:9000 可以看到check的project结果
注意:
If you get an java.lang.OutOfMemoryError, you can set the MAVEN_OPTS environment variable, like this in *nix environments: export MAVEN_OPTS="-Xmx512m" On Windows environments, avoid the double-quotes, since they get misinterpreted. set MAVEN_OPTS=-Xmx512m |