轉載務必說明出處:https://blog.csdn.net/LiaoHongHB/article/details/84785414
前提:開發環境已經安裝了Java1.8及以上,idea使用maven依賴,MySQL安裝完成。
sonarqube:下載路徑:http://www.sonarqube.org/downloads/
下載完成之後,以Windows-64位舉例;
點擊運行圖中.bat文件,然後地址欄輸入:localhost:9000;出現如下畫面表示安裝完成:
登陸用戶名:admin,密碼:admin
漢化:下載漢化包,然後將下載之後的漢化包粘貼到
重新運行,輸入地址欄,可以看到界面已經是中文的了。
接下來,MySQL新建db_sonar數據庫,然後打開安裝目錄下的/conf/sonar.properties文件,添加數據庫描述:
sonar.jdbc.url=jdbc:mysql://localhost:3306/db_sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance
sonar.jdbc.username=root
sonar.jdbc.password=****
修改maven配置文件,增加如下內容:
<profile>
<id>sonar</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<sonar.jdbc.url>jdbc:mysql://localhost:3306/db_sonar</sonar.jdbc.url>
<sonar.jdbc.driver>com.mysql.jdbc.Driver</sonar.jdbc.driver>
<sonar.jdbc.username>root</sonar.jdbc.username>
<sonar.jdbc.password></sonar.jdbc.password>
<sonar.host.url>http://localhost:9000</sonar.host.url>
</properties>
</profile>
至此,idea以外的操作都已經修改完畢,接下來是idea中的相關操作。
首先idea要下載安裝SonarLint:
setting --> plugins:安裝插件SonarLint 重啓生效;
setting --> SonarLint General Settings;然後:
然後在pom.xml文件中配置如下信息:
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.2</version>
</plugin>
等待項目加載完畢,然後:
控制檯打印出結果:
點擊鏈接即可查看項目的代碼質量: