Analyzing with SonarQube Scanner

By SonarSource – GNU LGPL 3 – Issue Tracker – Sources 

Download SonarQube Scanner 3.0.3
Compatible with SonarQube 5.6+ (LTS)

Linux 64 bit                Windows 64 bit               Mac OS X 64 bit               Any*

*SonarQube 서버가 요구하는 버전의 자바 가상 머신(Java Virtual Machine, JVM)이 이미 시스템에 설치 되어 있다고 가정합니다.

Table of Contents

기능

SonarQube Scanner는 SonarQube로 프로젝트를 분석하는 가장 기본적인 방법입니다.

설치

  1. 압축된 파일을 임의의 위치에 다운로드한 뒤 압축을 해제합니다. 이수 이 디렉토리를 <install_diectory>로 표기합니다.
  2. <install_directory>/conf/sonar-scanner.properties 파일을 수정하여 SonarQube 서버와의 연결을 설정합니다:

    #----- Default SonarQube server
    #sonar.host.url=http://localhost:9000
  3. <install_directory>/bin 디렉토리를 path 환경 변수에 추가합니다.
  4. sonar-scanner -h (Windows 플랫폼인 경우 sonar-scanner.bat -h) 명령을 실행하여 SonarQube Scanner가 정상적으로 설치되었는지 확인할 수 있습니다. 명령어 실행 결과는 아래와 같습니다:

    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

분석 과정에서 더 많은 로그 메시지를 표시하고자 하는 경우 command line 명령어 파라미터로 sonar.verbose 속성을 추가합니다: -Dsonar.verbose=true

사용

프로젝트의 루트 디렉토리에, 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


프로젝트 루트 디렉토리에서 다음 명령을 실행하면, 프로젝트 분석을 수행합니다:

sonar-scanner

샘플 프로젝트

github 디렉토리에서 샘플 프로젝트를 제공합니다. github 리포지토리의 샘플 프로젝트를 살펴보거나 다운로드할 수 있습니다. projects/language 디렉토리에서 샘플 프로젝트를 확인하십시오.


보안

분석을 수행하기 위해서는 Execute Analysis 권한을 가지고 있어야 합니다.

Anyone 그룹에 Execute Analysis 권한이 부여되어 있지 않거나, SonarQube 인스턴스의 인증 기능이 활성화 되어 있는 경우(forceAuthentication 속성값이 true로 설정됨), Execute Analysis 권한을 부여받은 사용자의 토큰을 sonar.login 속성값으로 사용해야 합니다(예: sonar-sacnner -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 이상을 필요로 함.

더 읽어 보기

© 2017-2018 Moses Kim.

별도의 언급이 없는 한, 이 스페이스의 컨텐츠는 크리에이티브 커먼즈 저작자표시-비영리-동일조건변경허락 4.0 국제 라이선스에 따라 이용할 수 있습니다.
SONARQUBE는 SonarSource SA의 트레이드 마크입니다. 모든 트레이트 마크 및 저작권은 각 소유자의 소유물입니다.

::: SonarQube 관련 문의 : 이메일 :::