First, the Environment configuration: 1, JDK Installation and configuration 2, MySQL database installation----directly call the server yard MySQL database, on this basis to create a new database sonar. The database configuration is as follows: 3, the sonar official website downloads the sonarqube version, chooses 5.6.3 version, the official website says is the long-term support, therefore chooses this version. Note that the Sonarqube corresponding sonar scanner version number is 2.8. can also use Sonar runner, in fact runner and scanner like. http://www.sonarqube.org/downloads/Download the sonarqube5.6.3 version and unzip to the corresponding directory, configure the environment variables:
4. After downloading the version of Sonar scanner2.8, unzip to the corresponding directory and configure the environment variables:
- sonar_scanner_home:d:\sonar\sonar-scanner-2.8\sonar-scanner-2.8
- Path:%sonar_scanner_home%\bin
- To configure the Conf/sonar-scanner.properties file:
#-----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=sonar
Sonar.jdbc.password=sonar
#-----PostgreSQL
#sonar. Jdbc.url=jdbc:postgresql://localhost/sonar
#-----MySQL
Sonar.jdbc.url=jdbc:mysql://172.168.1.4:3306/sonar?useunicode=true&characterencoding=utf8
5. Double-click D:\sonar\sonarqube-5.6.3\sonarqube-5.6.3\bin\windows-x86-64\StartSonar.bat to start the service, the following description service started successfully:
At this point, login http://localhost:9000/, the interface is as follows:
6, the default entry http://localhost:9000/display is in English, need to install Chinese plug-in package. Download the path to the Chinese plugin:
Administration--system-update center-available--Find Chinese pack installation.
Second, the project practice:
1, the project root directory to create sonar-project.properties, configured as follows:
The parameters are specific to your own project, language settings.
2, cmd switch to the project root directory, input Sonar-scanner run can:
3, after the end of the run, to Http://localhost:9000/view the test results, according to the test results to find problems in the code, analysis and processing, to optimize the code.
4. Problems encountered in practice procedures:
- Install the Chinese plug-in package consistent prompt installation pending, and finally restart the computer well, do not know why
- Sonar.properties After you configure the Web server to start the service successfully, the login http://localhost:9000/will not be able to open the Web page, currently does not solve the problem, not to configure this, the service can also start OK, Code success is not affected by this scan. If you have the same problem, please answer it, appreciate it!
Sonar static code scanning environment Construction (WINDOWS10)