CI series three: code review tool SonarQube installation and configuration

1. Linux installation and configuration of SonarQube

The operation of SonarQube depends on the JDK, install the JDK, refer to the blog (one of the CI series: JDK installation and configuration)

1. sftp upload file: sonarqube-5.6.6.zip, the specific upload process can refer to the blog (CI series one: JDK installation and configuration)

2. Move sonarqube-5.6.6.zip to the installation directory

# mv sonarqube-5.6.6.zip /usr/local

3. Switch to the installation directory

# cd /usr/local 

4. Unzip the zip

# unzip sonarqube-5.6.6.zip

5. Change the folder name

# sonarqube-5.6.6 sonarqube

6. Modify the configuration file sonar.properties, the modified configuration items are as follows

# cd /usr/local/sonarqube/conf
# vi sonar.properties
sonar.jdbc.username=root
sonar.jdbc.password=******
sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance
# SonarQube的三大服务的JVM配置,如果SonarQube起不开,或是启动缓慢,根据日志文件修改相应的配置
# web服务的JVM配置
sonar.web.javaOpts=
# 计算引擎服务的JVM配置
sonar.ce.javaOpts=
# 搜索引擎服务的JVM配置
sonar.search.javaOpts=

7. Start the SonarQube service

# cd /usr/local/sonarqube/bin/linux-x86-64/
# ./sonar.sh start

8. Monitor the log file to see the specifics of the startup

# cd /usr/local/sonarqube/logs
# tail -f sonar.log

9. The firewall opens port 9000. For details, please refer to the document: 2. MySQL installation and configuration

10. Browser access to SonarQube service, user name and password are both admin

http://192.168.2.131:9000

2. Windows installation and configuration sonar-runner-2.4.zip (the file is in the root directory of the D drive)

1. Unzip the file: sonar-runner-2.4.zip to the current folder

2. Configure system variables

2.1. Added system variable SONAR_RUNNER_HOME=D:\sonar-runner-2.4

2.2. Compile the system variable PATH, append ";%SONAR_RUNNER_HOME%\bin;" at the end

3. Configure the sonar-runner configuration file sonar-runner.properties and modify the following content

sonar.host.url=http://192.168.2.131:9000
sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8
sonar.jdbc.username=root
sonar.jdbc.password=******

4. Execute the test command sonnar-runner -v in any window, and the following results appear, indicating that the configuration is successful

> sonar-runner -v   
D:\sonar-runner-2.4
SonarQube Runner 2.4
Java 1.8.0_121 Oracle Corporation (64-bit)
Windows 10 10.0 amd64

3. Sonar-runner cooperates with SonarQube to review a Java Maven project

Java Maven project jdk_design_pattern, the root directory is E:\workspace\jdk_parent\jdk_design_pattern

1. In the project root directory, create the file sonar-project.properties and perform a simple configuration. The configuration content is as follows (only the commented part needs to be changed):

#项目key
sonar.projectKey=jdk_design_pattern
# 项目value
sonar.projectName=jdk_design_pattern
# 项目版本号
sonar.projectVersion=1.0
# 项目源码路径,多个源码包可用英文逗号隔开
sonar.sources=src
# 项目编译后代码所在路径,多个可用英文逗号隔开
sonar.java.binaries=target/classes
#源码的编程语言,python为py
sonar.language=java
#源码的编码方式
sonar.sourceEncoding=UTF-8
sonar.my.property=value

2. Right-click in the folder jdk_design_pattern, click the DOS fast channel, open CMD, and execute the following command to cooperate with SonarQube for code review:

> sonar-ruuner

3. After the analysis is completed, you can log in to the SonarQube service website: 192.168.2.131:9000 to view the code review results of the project

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325719460&siteId=291194637