이 문서는 SonarQube의 간단한 사용법에 대한 가이드를 공유하기 위해 작성되었다.
1. SonarQube 다운로드
아래 링크를 통해 SonarQube를 다운로드 받는다.
https://www.sonarqube.org/downloads/
2017년 11월 13일 기준 6.7 LTS 버전 다운로드
2. 다운로드 받은 파일을 적당한 폴더에 압축을 해제한다.
윈도우 예
C:\sonarqube |
리눅스 예
/etc/sonarqube |
3. SonarQube 서버를 시작한다.
윈도우 예
C:\sonarqube\bin\windows-x86-xx\StartSonar.bat |
리눅스 예
/etc/sonarqube/bin/[OS]/sonar.sh console |
4. SonarQub에 접속하기 위해 다음 URL로 접속한다.
5. 관리자 계정으로 로그인한다.
1. Sonar Scanner 다운로드
2. 다운로드 받은 파일의 적당한 위치에 압축을 해제한다.
윈도우 예
C:\sonar-scanner |
3. Sonarqube를 포인팅하기 위해 <설치경로>/conf/sonar-scanner.properties 를 Editor로 오픈한다.
아래와 같이 sonar.host.url=http://localhost:9000으로 SonarQube Host 위치로 수정한다.
#----- Default SonarQube server #sonar.host.url=http://localhost:9000 |
4. 환경 변수 Path에 bin 디렉토리 추가한다.
5. 다음과 같이 동작 여부를 점검한다.
D:\sonar-scanner\bin>sonar-scanner.bat -h INFO: INFO: usage: sonar-scanner [options] INFO: INFO: Options: INFO: -D,--define <arg> Define property INFO: -h,--help Display help information INFO: -v,--version Display version information INFO: -X,--debug Produce execution debug output |
6. SonarQube 분석을 위한 Code 위치로 이동
다음 링크에서 Sample 프로젝트를 다운로드 받을 수 있다.
7. sonar-project.properties 파일 생성
아래와 같이 sonar-project.properties 파일을 분석하고자 하는 root 디렉토리에 생성한다.
# must be unique in a given SonarQube instance # SonarQube에서 식별하는 프로젝트 키 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 |
8. sonar-scanner 명령으로 수행
d:\sonar-scanner\bin\sonar-scanner |
다음과 같이 Execution Success가 나타남.
SonarQube 접속 시 다음과 같이 결과를 보여줌.