sonar服務器端和客戶端的安裝和使用

本篇文章將sonar的安裝說明一下:
環境 1.JDK:1.8.0_60
2.sonarqube:sonarqube-5.4版本服務器(mysql5.5包括及以上)
3.sonar-runner:sonar-runner-2.3客戶端
4.操作系統 win8 64位
第一步:sonarqube-5.4 解壓即可使用,先配置配置文件。
配置:
1.sonarqube-5.4\conf中sonar.properties
1).mysql:先創建一個數據庫sonar,這裏root是指可以訪問這個庫的用戶。
sonar.jdbc.username=root
sonar.jdbc.password=root
sonar.jdbc.url=jdbc:mysql://127.0.0.1:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance
2.web啓動訪問端口:
sonar.web.port=9000
/sonarqube-5.4/bin/windows-x86-64/StartSonar.bat啓動
3.sonarqube-5.4/logs中可以看到啓動日誌
當看到Web server is startedHTTP connector enabled on port 9000Process[web] is up就說明啓動好了。
瀏覽器輸入:http://127.0.0.1:9000/
4.插件安裝
1)上述 進入http://127.0.0.1:9000/,默認用戶名和密碼:admin/admin
點擊配置菜單欄-》系統-》更新中心 可以下載插件:中文,checkstyle等,當下載不下來。可以選擇手動安裝。
2).手動安裝:git網址:https://github.com/SonarQubeCommunity
realease下載jar,放置到sonarqube-5.4/extensions/plugins下,重新啓動sonarqube就會安裝了。
2.第二步:解壓sonar-runner-2.3
配置環境變量到path。
SONAR_RUNNER_HOME:D:\Program Files\sonar-runner-2.3
path增加%SONAR_RUNNER_HOME%\bin;
3.需要使用sonar分析代碼的項目中增加配置文件sonar-project.properties
# Root project information
sonar.projectKey=allProjects
sonar.projectName=allProjects
sonar.projectVersion=1.0.0

# Some properties that will be inherited by the modules
sonar.sources=src

# List of the module identifiers
sonar.modules=a,b,c

# Properties can obviously be overriden for
# each module - just prefix them with the module ID
a.sonar.projectName=a1
b.sonar.projectName=b1
c.sonar.projectName=c1
ok!配置完成

下面使用sonar進行代碼分析了:
第一種方法:
maven:在settings.xml配置sonar中配置
<profile>
<id>sonar</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<sonar.jdbc.url>
jdbc:mysql://[sonar_db_host]:3306/sonar?useUnicode=trueamp;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>root</sonar.jdbc.password>
<sonar.host.url>[SonarQube_host]</sonar.host.url>
</properties>
</profile>
然後使用maven方式,goals爲sonar:sonar 第一個sonar表示maven的sonar插件,第二個sonar表示sonar插件中的sonar目標.
ok


第二種方法:
之前描述過安裝了sonar-runner-2.3客戶端而且也配置了環境變量。
所以可以直接使用命令行的方式進入需要分析代碼的項目代碼目錄下(目錄下配置好了sonar-project.properties文件,不然會報錯unknown Unable to load component class org.sonar.batch.scan.ProjectLock You must define the following mandatory properties for 'Unknown': sonar.projectKey, sonar.projectName, sonar.projectVersion),執行sonar-runner ok.

第三種方法:使用持續化集成工具jenkins/hudson
詳細的操作參見hudson的安裝使用篇!


備註參考網址:
maven插件:
http://www.infoq.com/cn/news/2011/05/xxb-maven-8-plugin
http://www.infoq.com/cn/news/2011/04/xxb-maven-7-plugin
sonar:
http://blog.csdn.net/yzhou86/article/details/41170669
http://www.ituring.com.cn/article/69556
maven與sonar結合:goals---->sonar:sonar
http://www.cnblogs.com/cuiliqiang/archive/2012/10/15/2725146.html

sonar 原理:
http://www.cnblogs.com/cuiliqiang/archive/2012/10/17/2727024.html
sonar 安裝:https://my.oschina.net/jiangbianwanghai/blog/478338?p=1
checkStyle 插件源碼https://github.com/checkstyle/sonar-checkstyle
sonar插件下載:https://github.com/SonarQubeCommunity
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章