1. 程式人生 > 程式設計 >無套路,3分鐘帶你輕鬆上手SonarQube - 程式碼質量檢測平臺

無套路,3分鐘帶你輕鬆上手SonarQube - 程式碼質量檢測平臺

前言

想成為一名優秀的工程師,程式碼質量一定要過關!

開始搭建

SonarQube

1、獲取 postgresql 的映象

$ docker pull postgres複製程式碼

2、啟動 postgresql

$ docker run --name db -e POSTGRES_USER=sonar -e POSTGRES_PASSWORD=sonar -d postgres複製程式碼

3、獲取 sonarqube 的映象

$ docker pull sonarqube複製程式碼

4、啟動 sonarqube

$ docker run --name sq --link db -e SONARQUBE_JDBC_URL=jdbc:postgresql://db:5432/sonar -p 9000:9000 -d sonarqube複製程式碼

至此,平臺搭建完畢。

程式碼質量檢驗

1、開啟 http://localhost:9000/,點選 "Log in"

sonar平臺

登入賬號:admin 密碼:admin

2、以 Maven 專案為例,此處有一個 security-oauth2-qq 專案:

Maven 專案

pom.xml 新增配置:

    <!-- 程式碼質量檢測 -->
    <profiles>
        <profile>
            <id>sonar</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <sonar.host.url>http://127.0.0.1:9000/</sonar.host.url>
            </properties>
        </profile>
    </profiles>複製程式碼

3、執行命令,檢測程式碼質量

$ mvn sonar:sonar複製程式碼

4、成功之後,返回到瀏覽器,就可以瀏覽自己的專案的程式碼質量了

綜合評分

Code Dashboard

精準分析

總結

目前碼雲上程式碼分析工具首推的也是 sonarqube,支援各種語言的程式檢測,使用簡單方便,感覺非常適合微服務的程式碼評審,強烈推薦。

原文連結:https://mp.weixin.qq.com/s?__biz=MzU0MDEwMjgwNA==&mid=2247486344&idx=1&sn=56ead0790135b91791494862192791d3&chksm=fb3f1273cc489b65d357212a63707f08c76c90bf7a80dc885ae93f328a0cf34bd3100560902a&token=1420633595&lang=zh_CN#rd

本文由部落格一文多發平臺 OpenWrite 釋出!