/
Analyzing with SonarQube Scanner for Maven

Analyzing with SonarQube Scanner for Maven

By SonarSource – GNU LGPL 3 – Issue Tracker  Sources

SonarQube Scanner for Maven 3.4.0.905

Table of Contents


기능

이 분석기는 Java Maven 프로젝트를 분석하는 경우 권장합니다.

호환성

Maven Version

2.x
3.x
Compatibility(error)(tick)

maven-sonar-plugin 3.4.0.905 부터 SonarQube v5.6 이전의 버전을 지원하지 않습니다.

Sonarqube v5.6 이전의 버전을 사용하는 경우, maven-sonar-plugin 3.3.0.603를 사용하십시오.

maven-sonar-plugin 3.1 부터 Maven v3.0 이전의 버전을 지원하지 않습니다.

Maven v3.0 이전의 버전을 사용하는 경우, maven-sonar-plugin 3.0.2를 사용하십시오.

사전 조건

  • Maven 3.x를 설치합니다.
  • SonarQube 서버를 설치합니다.
  • 사용하는 SonarQube 서버를 지원하는 최소한의 Java 버전(최신 LTS 버전의 경우, Java 8 필수)을 설치합니다.
  • 분석 대상 언어 분석 플러그인을 설치합니다.
  • 소스 코드 분석하기를 숙지합니다

초기 셋업

글로벌 설정

Maven의 settings.xml 파일($MAVEN_HOME/conf 혹은 ~/.m2 디렉토리에 위치)에 플러그인 prefix와 SonarQube Server URL을 설정합니다.

예:

<settings>
    <pluginGroups>
        <pluginGroup>org.sonarsource.scanner.maven</pluginGroup>
    </pluginGroups>
    <profiles>
        <profile>
            <id>sonar</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <!-- Optional URL to server. Default value is http://localhost:9000 -->
                <sonar.host.url>
                  http://myserver:9000
                </sonar.host.url>
            </properties>
        </profile>
     </profiles>
</settings>

Maven 프로젝트 분석하기

Maven 프로젝트를 분석하려면, pom.xml 파일이 있는 위치에서 sonar:sonar maven goal을 실행합니다:

$ mvn clean verify sonar:sonar
  
# In some situation you may want to run sonar:sonar goal as a dedicated step. Be sure to use install as first step for multi-module projects
$ mvn clean install
$ mvn sonar:sonar
 
# Specify the version of sonar-maven-plugin instead of using the latest. See also 'How to Fix Version of Maven Plugin' below.
$ mvn org.sonarsource.scanner.maven:sonar-maven-plugin:3.4.0.905:sonar

테스트 커버리지 정보를 얻기 위해서는 분석 전 커버리지 보고서를 생성해야 합니다. 자세한 정보는 Code Coverage by Unit Tests for Java Project 및 Code Coverage by Integration Tests for Java Project를 참조하십시오.

SonarQube 분석 설정하기

분석 파라미터를 참조해, 필요한 파라미터들을 설저합니다. pom.xml 파일의 <properties> 섹션에 다음과 같이 설정합니다:

<properties>
  <sonar.exclusions> [...] </sonar.exclusions>
</properties>

보안

Execute Analysis 권한을 가진 사용자는 분석을 수행할 수 있습니다.

Anyone 그룹이 Execute Analysis 권한을 가지고 있지 않거나, SonarQube 인스턴스에 보안 설정을 한 경우(sonar.forceAuthentication 속성을 true로 설정), sonar.login 속성값으로 Execute Analysis 권한을 가진 사용자의 분석 토큰값을 입력해야 합니다.

예: sonar-scanner -Dsonar.login=[my analysis token]


SonarQube 분석에서 모듈 제외하기

다음 방법 중 하나를 선택해하여 분석에서 모듈을 제외할 수 있습니다:

  • 분석에서 제외하고자 하는 모듈의 pom.xml에서 <sonar.skip>true</sonar.skip> 속성을 설정합니다.

  • 빌드 속성을 설정해 특정한 모듈을 제외합니다(integration tests 등)
  • Advanced Reactor Options ("-pl" 등)을 사용합니다(예: mvn sonar:sonar -pl !module2)

샘플 프로젝트

다음 링크에서 간단한 샘플 프로젝트를 다운로드 할 수 있습니다https://github.com/SonarSource/sonar-scanning-examples/tree/master/sonarqube-scanner-maven

메이븐 플러그인 버전 고정하기

메이븐 플러그인을 고정할 것을 권장합니다:

Project analyzed with Maven 3

<build>
  <pluginManagement>
    <plugins>
      <plugin>
        <groupId>org.sonarsource.scanner.maven</groupId>
        <artifactId>sonar-maven-plugin</artifactId>
        <version>3.4.0.905</version>
      </plugin>
    </plugins>
  </pluginManagement>
</build>

트러블 슈팅

java.lang.OutOfMemoryError가 발생하는 경우, MAVEN_OPTS 환경 변수를 아래와 같이 수정합니다:

  • *nix 계열 운영체제인 경우: export MAVEN_OPTS="-Xmx512m"
  • Windows 운영체제인 경우: set MAVEN_OPTS=-Xmx512m


Related content

Analyzing with SonarQube Scanner for Jenkins
Analyzing with SonarQube Scanner for Jenkins
More like this
Analyzing with SonarQube Scanner for Gradle
Analyzing with SonarQube Scanner for Gradle
More like this
Analyzing with SonarQube Scanner for MSBuild
Analyzing with SonarQube Scanner for MSBuild
More like this
Analyzing with SonarQube Scanner
Analyzing with SonarQube Scanner
More like this
Analyzing with SonarQube Scanner for Ant
Analyzing with SonarQube Scanner for Ant
More like this
SonarQube 9.0 릴리스
SonarQube 9.0 릴리스
More like this

© 2017-2018 Moses Kim.

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

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