SQ Official Doc Link: https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner
By SonarSource – GNU LGPL 3 – Issue Tracker – Sources Download SonarQube Scanner 3.0.3 Linux 64 bit Windows 64 bit Mac OS X 64 bit Any* *SonarQube 서버가 요구하는 버전의 자바 가상 머신(Java Virtual Machine, JVM)이 이미 시스템에 설치 되어 있다고 가정합니다. |
Table of Contents
기능
The SonarQube Scanner is recommended as the default launcher to analyze a project with SonarQube.
설치
- Expand the downloaded file into the directory of your choice. We'll refer to it as <install_directory> in the next steps.
Update the global settings to point to your SonarQube server by editing <install_directory>/conf/sonar-scanner.properties:
#----- Default SonarQube server
#sonar.host.url=http://localhost:9000
- Add the <install_directory>/bin directory to your path.
You can verify your installation by opening a new shell and executing the command
sonar-scanner -h
(on Windows platform the command issonar-scanner.bat -h
) . You should get output like this:usage: sonar-scanner [options]
Options:
-D,--define <arg> Define property
-h,--help Display help information
-v,--version Display version information
-X,--debug Produce execution debug output
If you need more debug information you can add the sonar.verbose
property by adding the command line parameter -Dsonar.verbose=true
.
사용
Create a configuration file in the root directory of the project: sonar-project.properties
sonar-project.properties# must be unique in a given SonarQube instance sonar.projectKey=my:project # this is the name and version displayed in the SonarQube UI. Was mandatory prior to SonarQube 6.1. sonar.projectName=My project 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. sonar.sources=. # Encoding of the source code. Default is default system encoding #sonar.sourceEncoding=UTF-8 |
Run the following command from the project base directory to launch the analysis:
sonar-scanner |
샘플 프로젝트
To help you get started, simple project samples are available for most languages on github. They can be browsed or downloaded. You'll find them filed under projects/languages.
보안
Any user who's granted Execute Analysis permission can run an analysis.
If the Anyone group is not granted Execute Analysis permission or if the SonarQube instance is secured (the sonar.forceAuthentication
property is set to true)
, the analysis token of a user with Execute Analysis permission must be provided through the sonar.login
property. Example: sonar-scanner -Dsonar.login=[my analysis token]
트러블 슈팅
Java heap space error or java.lang.OutOfMemoryError
,
SONAR_SCANNER_OPT 환경 변수 설정을 통해 메모리 증가:
export SONAR_SCANNER_OPTS="-Xmx512m" |
Windows 환경의 경우, 쌍따옴표(")를 제외하고 아래와 같이 입력:
set SONAR_SCANNER_OPTS=-Xmx512m |
Unsupported major.minor version
분석에 사용되는 Java 버전을 업그레이드하거나 네이티브 패키지를 활용함, SonarQube 5.6+은 Java 8 이상을 필요로 함.
Add Comment