SonarQube的历史版本下载地址:SonarQube历史版本下载地址
我的环境配置的是JDK8,安装SonarQube的版本是7.5
**
1.SonarQube的Windows环境的安装
**
下载sonarqube-7.5zip,并解压。进入解压目录的bin/windows-x86-64/目录下。双击StartSonar.bat进行Windows64系统的SonarQube的软件启动。
启动成功的结果:
出现下面两行,表示启动成功。
jvm 1 | 2020.03.11 14:46:42 INFO app[][o.s.a.SchedulerImpl] Process[ce] is up
jvm 1 | 2020.03.11 14:46:42 INFO app[][o.s.a.SchedulerImpl] SonarQube is up
访问localhost:9000就可以直接访问了
**
2. 汉化中文包
**
SonarQube7.5需要下载sonar-l10n-zh-plugin-1.25.jar文件
下载地址:sonar-l10n-zh-plugin-1.25.zip下载文件地址
下载下来的是zip文件,解压之后,在pom.xml文件目录下进行打包,执行mvn clean package命令,在target目录下找到该jar包。
把这个jar包放在SonarQube的安装路径的\extensions\plugins目录下,重新启动SonarQube服务,再访问localhost:9000就可以看到汉化的目录。
**
3. MySQL数据库配置
**
打开MySQL(我是用的是5.7版本),新建一个数据库(mysonar)
打开SonarQube安装目录下的\conf\sonar.properties文件
添加MySQL数据库连接信息和SonarQube的连接信息
#MySQL数据库连接地址
sonar.jdbc.url=jdbc:mysql://localhost:3306/mysonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance&useSSL=false
#MySQL数据库用户名
sonar.jdbc.username=root
#MySQL数据库密码
sonar.jdbc.password=wanghao
#SonarQube的编码
sonar.sorceEncoding=UTF-8
#SonarQube的登录名
sonar.login=admin
#SonarQube的登录密码
sonar.password=admin
重新启动SonaQube,启动的时间会长一点,因为要在MySQL数据库中初始化表
StartSonar.bat出现下面的代码,表示SonarQube启动成功
jvm 1 | 2020.03.11 15:00:36 INFO app[][o.s.a.SchedulerImpl] Process[ce] is up
jvm 1 | 2020.03.11 15:00:36 INFO app[][o.s.a.SchedulerImpl] SonarQube is up
**
4. maven配置
**
maven的配置文件中需要添加sonar的以下的配置
<pluginGroups>
<pluginGroup>org.sonarsource.scanner.maven</pluginGroup>
</pluginGroups>
<profile>
<id>sonar</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<sonar.host.url>http://127.0.0.1:9000</sonar.host.url>
<sonar.login>admin</sonar.login>
<sonar.password>admin</sonar.password>
</properties>
</profile>
**
5. idea配置
**
idea需要添加SonarLine插件,安装完成重启。
**
6. 项目配置
**
创建一个SpringBoot的简单项目
在pom.xml文件中添加Sonar的插件
<build>
<finalName>test</finalName>
<plugins>
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.2</version>
</plugin>
</plugins>
</build>
在Run/Debug Configurations菜单中,添加一个maven
输入sonar分析的命令,然后Apply,OK
clean verify sonar:sonar
Idea开始分析:
启动结果:
访问:http://localhost:9000,登陆账号和密码都是admin。在首页就可以看到你想要分析的项目的结果。