This is the 25th day of my participation in the August Challenge

Sonar is a code detection tool that you can use if you want to monitor your team’s code writing during development. Sonar provides a visual interface (you can fake x with your boss) and is a tool that can be both useful and useful to show off in the company. If you are a leader in the company, and want to be in the top position, you can land and improve your sense of existence… Without further ado, let’s begin.

1. Concept interpretation

Sonar is a code quality check middleware, but during the installation process, there were many concepts, let me confused. Here’s how to distinguish these concepts.

 1.sonarqube

Sonarqube: Is an automated code review tool that detects errors, bugs, and formatting problems in code. It can be integrated with your existing workflow to enable continuous code reviews across project branches and extract requests. A visual management page is also provided to view the detected results.

Sonarqube also provides a set of specifications (about 300, not recommended) that can be checked to enable or disable detection.

That is, Sonarqube is just a display platform that needs to be connected to code in order to scan.

2.sonarlint

Sonarlint is a plugin for IDEA. Sonarlint also has a check function, which can check code in IDEA and configure check specifications in IDEA. Sonarlint can also connect to Sonarqube, just using the front page of Sonarqube.

The test results

Test specification (can be controlled by checking)

3.sonar-scanner

Sonarqube: Sonar – Scanner plugin for scanning code and connecting to Sonarqube, you can connect local code to Sonarqube using sonar-scanner plugin and the results will be displayed in Sonarqube.

Sonarqube detects code Java code in two ways, one using Sonar-scanner and one using SonarLint, as described below.

4.p3c

P3c: There are about 50 code format specifications specified by Alibaba, which can be used in IDEA or imported into Sonarqube and then detected by Sonarqube

Recommend using P3C rules, sonar rules is too complex, any code can give you errors.

2. Install

Because the company had only one Windows server left, so… Boss you feel purchase memory !!!!

1. Install the JDK

Refer to the previous documentation.

2. Download and decompress

Download address:www.sonarqube.org/downloads/, circled in red for the community edition (free).

3. Install the database

Install the database according to your needs.

4. Prepare data

Create sonar library with sonar user.

5. Modify the configuration file

Login =root sonar. Password =root sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar? useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance&useSSL=false sonar.jdbc.username=sonar sonar.jdbc.password=sonarCopy the code

Note If the following error occurs, note the mysql version and mysql account password

2021.04.06 10:50:09 WARN APP [][O.E.t.n.netty4transport] exception Caught on Transport Layer [[ID: 0x29E09CD2, L:/127.0.0.1:52892 -r :/127.0.0.1:9001]], closing Connection Java.io.IOException: The remote host forced an existing connection to close.Copy the code

6. Start

Select the Windows version.Click the BAT script in order.If the following message is displayed, the installation is successful.

7. Login

Access address ishttp://localhost:9000, click Login and enter the login account and password configured above.

8. Install the plug-in

The download address of the Sinicized plug-in is:Github.com/xuhuisheng/…Download your own JAR packages based on the versionAfter downloading the JAR package, copy the JAR package to sonarqube-7.6\ Extensions \plugins and restart it.