SonarQube, Sonar-Scanner environment to build and use

SonarQube build and use tutorial

SonarQube download

sonar official website: https://www.sonarqube.org/
sonar download link: https://www.sonarqube.org/downloads/

SonarQube installation

Preconditions:
1. Java environment (1.8+)
2. MySql database (5.6+)
3. SonarQube 7.6 is
downloaded and decompressed after the rendering is as follows:
Insert picture description hereenter the conf file, configure sonar.properties, and the parameter information is as follows:

sonar.jdbc.username=root
sonar.jdbc.password=123123
sonar.jdbc.url=jdbc:mysql://localhost:3307/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance&useSSL=false
sonar.web.port=9000

Insert picture description hereEnter the bin folder, the effect is as follows:
Insert picture description here
it supports various operating systems, select your current operating system, the effect is as follows:
Insert picture description hereexecute in order, InstallNTService.bat, StartNTService.bat, StartSonar.bat files, if there is no error, After the startup is successful, visit: http://localhost:9000 , the effect is as follows: At
Insert picture description herethis point, SonarQube is installed successfully

SonarQube Chinese Settings

Insert picture description here
Restart the project

Sonar-Scanner installation and use

The sonar-scanner plug-in is used to analyze the software and is used in conjunction with SonarQube.

Sonar-Scanner download

Download link: https://sonarsource.bintray.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-3.0.3.778-windows.zip

Unzip and use

Sonar-Scanner configuration and use

Configure environment variables:

Create a new system variable:
SONAR_SCANNER_HOME=Sonar Scanner root directory.
Modify the system variable path and add %SONAR_SCANNER_HOME%\bin (you can add path directly without creating SONAR_SCANNER_HOME);

Open the cmd panel, enter sonar-scanner -version, the following figure appears, it means that the environment variable is set successfully:
Insert picture description here

Modify sonar-scanner.properties under conf and configure as follows:

sonar.host.url=http://localhost:9000(sonar地址)
sonar.sourceEncoding=UTF-8
sonar.jdbc.url=jdbc:mysql://localhost:3307/sonarqube?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance&useSSL=false
sonar.jdbc.username=******
sonar.jdbc.password=*******

Create a new sonar-project.properties in the root directory of the project to be detected, with the following content:

sonar.projectKey=your_project(自己定义)
sonar.projectName=your_project(自己定义)
sonar.projectVersion=1.0
sonar.sources=src(代码目录)
sonar.java.binaries=target(classes文件目录,不加会报错)
sonar.language=java
sonar.sourceEncoding=UTF-8

Then, open the command line in the project root directory, enter sonar-scanner to run, you can see that the detection is successful, and you can see the detection results on the sonar homepage. The effect diagram is as follows:

Insert picture description here

Guess you like

Origin blog.csdn.net/yang520java/article/details/107176493