intelij idea使用sonar

使用原因

   寫了一大片代碼,成功感肯定是有的,但是之後代碼檢查時,由於代碼可能比較多、亂,自己也不想去檢查,intelij idea安裝sonar後,sonar可以幫我發現一些簡單的錯誤,比如:變量未使用、無用代碼、請求返回沒有處理、某些使用方式錯誤等

準備工作

1、sonarqube:http://www.sonarqube.org/downloads/

2、SonarQube+Scanner:https://sonarsource.bintray.com/Distribution/sonar-scanner-cli/sonar-scanner-2.5.zip

安裝sonar

 1.運行sonarqube,進入安裝目錄:D:\sonarqube-5.3\bin\windows-x86-64,然後點擊StartSonar.bat

2.訪問sonarqube,在自己的瀏覽器上輸入:http://127.0.0.1:9000,出現下圖,說明成功了

intelij idea配置

1. intelij idea安裝sonar插件,File->Settings->Plugins->Search in respositories,查詢框輸入“sonar”,選擇SonarLint,點擊install,最後重啓intelij idea,就安裝成功

2. setting文件修改,右擊項目工程,選擇Maven->Open ‘Settings.xml’

<profile>
            <id>sonar</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <sonar.jdbc.url>
                    jdbc:mysql://localhost:3308/localhost?useUnicode=true&characterEncoding=utf8
                </sonar.jdbc.url>
                <sonar.jdbc.driver>com.mysql.jdbc.Driver</sonar.jdbc.driver>
                <sonar.jdbc.username>root</sonar.jdbc.username>
                <sonar.jdbc.password>123456</sonar.jdbc.password>
                <sonar.host.url>http://localhost:9000</sonar.host.url>
            </properties>
</profile>

3. 分析代碼

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章