天天看點

SonarQube安裝及使用(idea內建&linux安裝注意事項)

1.需要安裝的軟體:

a.sonarqube(6.7.3)       
   下載下傳位址:http://www.sonarqube.org/downloads/
  b.sonar-runner(2.5)
   下載下傳位址:https://sonarsource.bintray.com/Distribution/sonar-scanner-cli/sonar-scanner-2.5.zip
  c.Mysql(5.6及以上)
  d.jdk(1.8用于內建idea)
           

 2.啟動及配置:

a.單獨啟動SonarQube路徑:  sonarqube-6.7.3\bin\windows-x86-64\StartSonar.bat
      TIP:我出現過遠端連接配接強行被關閉的問題,後版本改為6.7.3解決
  b.通路位址:http://localhost:9000
  c.建立資料庫:sonar(每次檢查的結果都會自動存入資料庫)
  d.配置SonarQube\conf\sonar.properties檔案
        sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8
            &rewriteBatchedStatements=true&useConfigs=maxPerformance
	sonar.jdbc.username=使用者名
	sonar.jdbc.password=密碼
	sonar.sorceEncoding=UTF-8
	sonar.login=admin
	sonar.password=admin
  e.重新開機服務再次通路9000端口(如果出現被占用的情況,右鍵工作列-檔案管理器-清除所有JavaSE的程序,一般是三個)
  f.安裝中文插件:配置-->應用市場-->搜尋chinese pack -->install 重新開機生效
  	TIP:建議安裝 SonarJS SonarJava SonarTS
                  TIP:建議安裝 SonarJS SonarJava SonarTS
        

 3.idea內建SonarQube

    a.setting --> plugins:安裝插件SonarLint 重新開機生效

    b.setting --> SonarLint General Settings

SonarQube安裝及使用(idea內建&linux安裝注意事項)

    c.建立令牌:

SonarQube安裝及使用(idea內建&linux安裝注意事項)

    d.update binding (出現過Tyscript版本過低問題,更新SonarTS即可)

SonarQube安裝及使用(idea內建&linux安裝注意事項)

 4.運作SonarQube進行codeView

    a.單個檔案檢查:點選檔案,代碼界面右鍵Analyze With SonarLint

    b.多個檔案檢查:SonarLint tool --> Report -->檔案夾圖示

SonarQube安裝及使用(idea內建&linux安裝注意事項)

    c.maven指令啟動,檢查結果會顯示在伺服器中

maven-setting.xml添加:
  	<profile>
      <id>sonar</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <properties>
        <sonar.jdbc.url>jdbc:mysql://localhost:3306/sonar</sonar.jdbc.url>
        <sonar.jdbc.driver>com.mysql.jdbc.Driver</sonar.jdbc.driver>
        <sonar.jdbc.username>root</sonar.jdbc.username>
        <sonar.jdbc.password>832231</sonar.jdbc.password>
        <sonar.host.url>http://localhost:9000</sonar.host.url>
      </properties>
    </profile>

    pom.xml添加:
    <build>
        <plugins>
            <plugin>
                    <groupId>org.sonarsource.scanner.maven</groupId>
                    <artifactId>sonar-maven-plugin</artifactId>
                    <version>3.2</version>
            </plugin>
        </plugins>
    </build>

    運作指令:先clean install 後 sonar:sonar 服務端會顯示相關代碼問題
           

結果展示:

SonarQube安裝及使用(idea內建&amp;linux安裝注意事項)

linux安裝:

    a.建議使用sonarqube 6.5版本 ,因為sonarqube自帶es ,版本大于6.5 的不支援root啟動es,大于6.5可以通過建立其他使用者啟動es來解決這個問題

    b.其次啟動linux-x86-x64下面的sonar.sh,啟動指令為./sonar.sh start(stop,console,restart)

    c.如果發現提示sonarqube已啟動,但是通路沒有效果,檢視sonar/logs下面的日志,主要是es.log sonar.log和web.log,其中必有出錯原因

    d.如果出現更新中心不能通路的問題,建議自己下載下傳中文插件包(需要對應版本号,否則無法啟動),我的是6.5對應1.17版本

    e.将sonarqube裝置開機自啟,因為不是服務,是以選擇加入啟動指令,

        vim/etc/rc.local   添加 /usr/java/sonar/bin/linux-x86-64/sonar.sh start

                                                                                                                                                         end

                                                                                                                                                         22.30 

                                                                                                                                                         2018.5.15

繼續閱讀