Environment to prepare


Built-in database

After the success of the Sonar installation, the default built-in H2 database, used to record a single scan results, for the same project repeat scan code, overwrite the previous scan, so the H2 database only applied to the test, can not be used in the production environment, that if you want to play, don’t want to scan your project for a long time, can don’t need to configure the database


Custom database:

  • Oracle
  • SQL Server (SQL Server 2014 and SQL Server2016 only)
  • PostgreSQL
  • MYSQL 8.0>MYSQL>=5.6

**End of Life of Mysql Support SonarQube 7.9 and future versions do not support MySQL. Please migrate to a supported database. Get more details at ** Community.sonarsource.com/t/end-of-li… Jira.sonarsource.com/browse/SONA…

Installation steps


1. Install sonarqube:

Install Windows 7.4 community community edition binaries.sonarsource.com/Distributio… I used the latest version 8.2 before, but there were many problems, and the evaluation said that the latest version was not very stable and did not support mysql. Finally, I used version 7.4, which was slow to download from the official website. If you cannot download it, you can leave a message and reply to me, or follow the qr code at the end of this article and send me a private message.

2. Install the JDK:

I installed JDK11(version 1.8 does not install sonarqube 8.2, 7.x is ok, you need to pay attention to the selection) if you can’t find the download address, private message me.

3. Select a database


4. Configuration:

  1. After installation, open the directory and run startsonar.bat

2. Start the browser and visit http://localhost:9000. If the following figure is displayed, the installation is successful.

3. Configure the connection to the database: open the sonary. properties file under the conf folder and add the following at the bottom:

If SQL Server is used, append:

  • Sonar, the JDBC url = JDBC: essentially: / / 10.60.215.202; databaseName=sonar
  • sonar.jdbc.username=sa
  • sonar.jdbc.password=123456

If it is MYSQL:

  • Sonar, the JDBC url = JDBC: mysql: / / 10.60.253.34:3306 / sonar? useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance&useSSL=false
  • sonar.jdbc.username=root
  • sonar.jdbc.password=123456
  • sonar.sorceEncoding=UTF-8
  • sonar.login=admin
  • sonar.password=admin

    4. Restart the system, that is, run startsonar. bat again and log in to the system as admin. After the database is configured, it initializes the table information and waits for a period of time.


5. Create project in Sonar and configure commands


Scanning results:


Lifecycle – Mapping JAR can’t be found

Git clone github.com/mfriedenhag… , then the MVN Package installs the missing package.

Integrate Alibaba P3C


How to use this guide to standardize our project code, we can introduce the sonar- P3c open source plugin, the following steps:

Build SONAR – P3C Plugin


Specific steps


A. packaged branch

Git clone –single branch –branch p3C-PMD-1.3.6-branch github.com/rhinoceros/…

After clone, pack

mvn clean install -Dgpg.skip=true

B. packaged plugin

Git clone github.com/rhinoceros/…

After clone, pack

mvn clean package

Deploy the P3C plug-in


Click Quality Benjamin and click Create

Select Java and name it

Click on the Active More

The filter on the left searches for P3C and selects Bulk Change to add P3C rules to the newly created profile

Go back to Quality Profiles and set the profile you just set to default

At this point, p3C rules are successfully integrated into Sonar. Now test:

Click Create New Project

Select Java, and generate token, generate MVN command, Copy, execute directly in the project

Idea scan will be very fast, Sonar will always show In Progress, need to wait for the analysis results. The result after successful execution is as follows, indicating that P3C has successfully checked our code

















More good articles, follow the author:


This article is published by OpenWrite, a blogging tool platform