使用Sonar-Scanner掃描Maven項目(前提已經安裝好SonarQube)


(前提:SonarQube已部署到服務器中,IP地址為xxx.xxx.xxx.xxx:9000)

1.配置Sonar Scanner的sonar鏈接,為SonarQube在服務器上的的運行鏈接,打開sonar-scanner-4.5.0.2216-windows\conf\sonar-scanner.properties,將鏈接填入打碼部分

 

 Sonar Scanner已經配置好了,開始審計代碼

2. 在Sonar中新建分析項目

起一個獨特響亮不平庸的名字

 

 

生成用於項目審計時,Sonar驗證Scanner請求時的唯一token,

 

 

 

 我大多都是Maven項目,所以選擇Maven,可以自己視情況而定

 

 Sonar自動生成掃描命令,點擊Copy在項目文件夾下運行該命令。不要相信這糟老頭子的鬼話,粘貼命令前,需要把\刪除

 

 如果粘貼命令后運行報找不到分析路徑與classes文件,則在被分析項目下添加sonar-project.properties文件,手動寫入分析路徑、分析的代碼語言、token、項目名稱

# your authentication token
sonar.login=生成的token

# must be unique in a given SonarQube instance
sonar.projectKey=test
# this is the name and version displayed in the SonarQube UI. Was mandatory prior to SonarQube 6.1.
sonar.projectName=test
sonar.projectVersion=1.0

# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
# This property is optional if sonar.modules is set. 
# Comma-separated paths to directories containing source files.
# 限定要分析的路徑
sonar.sources=.
sonar.java.binaries=target/classes

# Encoding of the source code. Default is default system encoding
sonar.sourceEncoding=UTF-8

# Set the language of the source code to analyze
# 限定要分析的代碼語言,比如js。
# 不設置則默認分析多種語言
sonar.language = java
sonar.sourceEncoding=UTF-8
sonar.scm.disabled=true

開始分析項目代碼

 

 Sonar生成審計結果

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM