preface

Want to become a good engineer, code quality must pass!

Begin to build

SonarQube

1. Obtain the postgresQL image

$ docker pull postgresCopy the code

2. Start PostgresQL

$ docker run --name db -e POSTGRES_USER=sonar -e POSTGRES_PASSWORD=sonar -d postgresCopy the code

3. Obtain sonarqube’s mirror image

$ docker pull sonarqubeCopy the code

4. Start Sonarqube

$ docker run --name sq --link db -e SONARQUBE_JDBC_URL=jdbc:postgresql://db:5432/sonar -p 9000:9000 -d sonarqubeCopy the code

At this point, the platform is completed.

Code quality inspection

1. Open http://localhost:9000/ and click “Log in”

Sonar platform

Login account: admin Password: admin

2. Take Maven project as an example, here is a security-oAuth2-QQ project:

Maven project

Pom.xml add configuration:

<! Sonar </ ID > <activation> <activeByDefault> True </activeByDefault> </activation> <properties> < sonary.host. url>http://127.0.0.1:9000/</ sonary.host. url> </properties> </profile> </profiles>Copy the code

3. Execute commands to check code quality

$ mvn sonar:sonarCopy the code

4. Once successful, go back to the browser and see the code quality of your project

The comprehensive score

Code Dashboard

Accurate analysis

conclusion

At present, sonarqube is also the first code analysis tool on the code cloud, which supports program detection in various languages. It is simple and convenient to use, and feels very suitable for microservice code review, which is strongly recommended.

Original link: https://mp.weixin.qq.com/s?__biz=MzU0MDEwMjgwNA==&mid=2247486344&idx=1&sn=56ead0790135b91791494862192791d3&chksm=fb3f127 3cc489b65d357212a63707f08c76c90bf7a80dc885ae93f328a0cf34bd3100560902a&token=1420633595&lang=zh_CN#rd

This article is published by OpenWrite!