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

    c.創建令牌:

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

 

 4.運行SonarQube進行codeView

    a.單個文件檢查:點擊文件,代碼界面右鍵Analyze With SonarLint

    b.多個文件檢查:SonarLint tool --> Report -->文件夾圖標

    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 服務端會顯示相關代碼問題

結果展示:

 

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

        

 

 

 

 

 

 

 

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