最近對SonarQube進行了一點學習,從網絡上查詢了不少的文章,而後本身又進行了各類實踐,終於成功的實現了代碼掃描。
首先咱們須要去SonarQube的官網進行下載,我這裏下載的是最新的版本8.0,固然本身按照本身的喜愛進行版本的下載便可:mysql
安裝嘛根本就沒有了,直接找個位置解壓縮就能夠了。sql
找到本身的系統版本運行對應的StartSonar.bat:
運行界面以下:
這時能夠看一下http://localhost:9000這個地址頁面了:
固然我以前運行過了,因此可能和大家顯示的不太同樣,不過不要緊,能顯示信息就能夠了:
而後咱們能夠登陸,用戶名和密碼就是admin,admin.數據庫
若是你對英語不是很敏感的話,那就能夠用到接下來的漢化教程了:
按照步驟進行操做:
安裝完畢後點擊重啓便可:
等一會會讓你再次登陸,而後就變成漢語啦:網絡
還有就是須要特別注意如下幾個點:oracle
在window沒有辦法經過命令進行SonarQube的中止或者重啓,只能粗暴的中止進程,而後再次運行StartSonar.bat:maven
找到SonarQube裏面config文件夾下面的sonar.properties配置文件,進行數據庫信息的配置:ide
sonar.jdbc.username=用戶名 sonar.jdbc.password=密碼 sonar.jdbc.url=jdbc:postgresql://localhost:5432/sonarqube
由於我這裏是掃描的maven工程,因此須要在maven配置文件中進行相關的設置:post
<profile> <id>sonar</id> <activation> <activeByDefault>true</activeByDefault> </activation> <properties> <sonar.jdbc.url> jdbc:postgresql://localhost:5432/sonarqube </sonar.jdbc.url> <sonar.jdbc.driver>org.postgresql.Driver</sonar.jdbc.driver> <sonar.jdbc.username>用戶名</sonar.jdbc.username> <sonar.jdbc.password>密碼</sonar.jdbc.password> <sonar.host.url>http://localhost:9000</sonar.host.url> </properties> </profile> </profiles>
配置完畢以後須要根據以前說的那樣將SonarQube重啓。學習
上面已經配置好了maven環境變量,而後在須要掃描的項目路徑下執行如下maven命令,便可掃描項目代碼:ui
mvn clean verify sonar:sonar
會執行不少東西,等到執行完畢以後就能夠去http://127.0.0.1:9000/sonar查看了:
好了就是這樣了。。。
安裝SonarLint插件便可:
在IDEA的左下角就會出現這個了,能夠查看代碼的問題
說實話,感受沒有阿里巴巴的代碼掃描好用,我的看法。。。
剛纔SonarQube發佈了8.0版本,我以前是7.9.1版本,本着能用就用最新的理念。我就下載並替換了8.0版本,但是啓動的時候出現了:
SonarQube is under maintenance. Please check back later. Whilst waiting, you might want to check new plugins to extend the current functionality. If you are an administrator and have no idea why this message is showing, you should read the upgrade guide
這裏表示很懵B呀,因而百度到升級方法就是:
http://127.0.0.1:9000/setup 按照提示更新下SonarQube就能夠啦,固然地址確定要是你本身的地址了。