SonarScanner integrates the perfect solution for SonarQube code quality inspection

1. Chinese SonarQube

Although the SonarQube service has been built, the interface is in English; it is not beneficial for those whose native language is Chinese to check the relevant indicators. In fact, SonarQube provides a Chinese plug-in package for internationalization.

  • Download plugin
https://github.com/xuhuisheng/sonar-l10n-zh
复制代码

The download is a jar package:sonar-l10n-zh-plugin-9.3.jar

  • Install

Put the jar directly in the following directory

C:\jenkins\sonarqube-9.3.0\extensions\plugins
复制代码

Then restart the service, you can see the Chinese interface.

picture

There is another simple Chinese plug-in installation method (other plug-ins can also be installed in this way), that is, after logging in to SonarQube, install it as shown below\

picture

2. SonarScanner for code inspection

Enter the following directory

C:\jenkins\SpringBoot_v2
复制代码

Then open a cmd command line window and execute the command in this directory

sonar-scanner
复制代码

picture

The error says that authentication is required to log into SonarQube. sonar-project.propertiesAdd the following configuration\

sonar.login=admin
sonar.password=admin123
复制代码

After adding, continue scanning

picture

The error in the above figure appears, sonar.java.binaries is the directory of the compiled class file of the project, and you need to continue to add configuration\

sonar.java.binaries=./target/classes
复制代码

./target/classesMust be an existing directory. Normally, the project code downloaded from the svn or git server does not have a classes directory. can be directly configured as

sonar.java.binaries=.
复制代码

sonar-project.propertiesThe full configuration is as follows

sonar.projectKey=SpringBoot_v2:1.0
sonar.projectName=SpringBoot_v2
sonar.projectVersion=1.0
sonar.sources=src
sonar.sourceEncoding=UTF-8
sonar.login=admin
sonar.password=admin123
sonar.java.source=1.8
sonar.java.binaries=./target/classes
复制代码

In addition, the sonar.login and sonar.password configuration items can also use the token mode, which will be explained later.

3. View code inspection results on SonarQube

After the sonar-scannercommand is executed, log in

http://localhost:9000/
复制代码

picture

At this point, the integration of SonarScanner and SonarQube for code quality scanning is OK. \

In addition, SonarScanner provides integration with tools such as eclipse, idea, jenkins, etc.

\

Guess you like

Origin juejin.im/post/7079375893600305159