Analyzing with SonarQube Scanner for Ant

By SonarSource – GNU LGPL 3 – Issue Tracker  Sources 

SonarQube Scanner for Ant 2.5 – Compatible with SonarQube 5.6+ (LTS) 
Download

Table of Contents

κΈ°λŠ₯

SonarQube Scanner for Antλ₯Ό μ‚¬μš©ν•΄ Apache Ant λΉŒλ“œ μŠ€ν¬λ¦½νŠΈμ—μ„œ SonarQube 뢄석을 μˆ˜ν–‰ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

ν˜Έν™˜μ„±

SoanrQube Scanner for Ant v2.5λŠ” SonarQube 5.6+와 ν˜Έν™˜λ©λ‹ˆλ‹€.

사전 μ€€λΉ„

  • SonarQubeκ°€ μ„€μΉ˜λ˜μ–΄ μžˆμ–΄μ•Ό ν•©λ‹ˆλ‹€
  • SonarQube μ„œλ²„κ°€ μ§€μ›ν•˜λŠ” μ΅œμ†Œ λ²„μ „μ˜ Javaκ°€ ν•˜λ‚˜ 이상 μ„€μΉ˜λ˜μ–΄ μžˆμ–΄μ•Ό ν•©λ‹ˆλ‹€
  • 뢄석 λŒ€μƒ μ–Έμ–΄μ˜ μ–Έμ–΄ ν”ŒλŸ¬κ·ΈμΈμ΄ μ„€μΉ˜λ˜μ–΄ μžˆμ–΄μ•Ό ν•©λ‹ˆλ‹€
  • μ†ŒμŠ€ μ½”λ“œ λΆ„μ„ν•˜κΈ°λ₯Ό μˆ™μ§€ν•©λ‹ˆλ‹€
  • Ant v1.7.1+

μ„€μΉ˜

뢄석을 μˆ˜ν–‰ν•  머신에 SonaQube Scanner for Antλ₯Ό λ‹€μš΄λ‘œλ“œ ν•©λ‹ˆλ‹€.

μ‚¬μš©

SonarQube Scanner for AntλŠ” Ant νƒœμŠ€ν¬λ‘œ SonarQube Scanner의 wrapperμž…λ‹ˆλ‹€. 이 warpperλŠ” SonarQube Scannerλ₯Ό ν˜ΈμΆœν•˜κ³ , sonar.* 의 νŒŒλΌλ―Έν„°λ₯Ό SonarQube Scanner둜 μ „λ‹¬ν•©λ‹ˆλ‹€. Any슀러운 λ°©λ²•μœΌλ‘œ λ™μž‘ν•˜μ§€λŠ” μ•Šμ§€λ§Œ, μƒˆλ‘œμš΄ ν”ŒλŸ¬κ·ΈμΈ ν˜Ήμ€ SonarQube μžμ²΄κ°€ μ œκ³΅ν•˜λŠ” νŒŒλΌλ―Έν„°λ“€μ„ μ¦‰μ‹œ ν™œμš©ν•  수 μžˆλŠ” μž₯점이 μžˆμŠ΅λ‹ˆλ‹€. 즉, SonarQube Scanner for Antλ₯Ό μ„±κ³΅μ μœΌλ‘œ ν™œμš©ν•˜λ €λ©΄ property 이름을 μ€€μˆ˜ν•΄μ•Ό ν•©λ‹ˆλ‹€.

뢄석 νŒŒλΌλ―Έν„° νŽ˜μ΄μ§€λ₯Ό μ°Έμ‘°ν•΄ Ant 기반의 뢄석 νŒŒλΌλ―Έν„°λ“€μ„ μΆ”κ°€λ‘œ 확인할 수 μžˆμŠ΅λ‹ˆλ‹€.

Simple Project

Ant λΉŒλ“œ μŠ€ν¬λ¦½νŠΈμ— sonar Ant νƒ€κ²Ÿμ„ μ •μ˜ν•©λ‹ˆλ‹€:

build.xml
<project name="My Project" default="all" basedir="." xmlns:sonar="antlib:org.sonar.ant">
...
  
<!-- Define the SonarQube global properties (the most usual way is to pass these properties via the command line) -->
<property name="sonar.host.url" value="http://localhost:9000" />
 
...
  
<!-- Define the SonarQube project properties -->
<property name="sonar.projectKey" value="org.sonarqube:sonarqube-scanner-ant" />
<property name="sonar.projectName" value="Example of SonarQube Scanner for Ant Usage" />
<property name="sonar.projectVersion" value="1.0" />
<property name="sonar.sources" value="src" />
<property name="sonar.java.binaries" value="build" />
<property name="sonar.java.libraries" value="lib/*.jar" />
...
 
<!-- Define SonarQube Scanner for Ant Target -->
<target name="sonar">
    <taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml">
        <!-- Update the following line, or put the "sonarqube-ant-task-*.jar" file in your "$HOME/.ant/lib" folder -->
        <classpath path="path/to/sonar/ant/task/lib/sonarqube-ant-task-*.jar" />
    </taskdef>
 
    <!-- Execute SonarQube Scanner for Ant Analysis -->
    <sonar:sonar />
</target>
...

ν”„λ‘œμ νŠΈ 베이슀 λ””λ ‰ν† λ¦¬μ—μ„œ λ‹€μŒ λͺ…λ Ήμ–΄λ₯Ό μ‹€ν–‰ν•˜λ©΄ 뢄석이 μˆ˜ν–‰λ©λ‹ˆλ‹€:

ant sonar

λ³΄μ•ˆ

Execute Analysis κΆŒν•œμ„ 가지고 μžˆλŠ” μ‚¬μš©μžλŠ” λˆ„κ΅¬λ‚˜ 뢄석을 μˆ˜ν–‰ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

Anyone 그룹에 Execute Analysis κΆŒν•œμ΄ λΆ€μ—¬λ˜μ–΄ μžˆμ§€ μ•Šκ±°λ‚˜, SonarQube μΈμŠ€ν„΄μŠ€μ— λ³΄μ•ˆ 섀정이 된 κ²½μš°μ—λŠ”(sonar.forceAuthentication=true) Execute Analysis κΆŒν•œμ„ 뢀여받은 μ‚¬μš©μžμ˜ 토큰값을 sonar.login μ†μ„±κ°’μœΌλ‘œ μ„€μ •ν•΄μ•Ό ν•©λ‹ˆλ‹€.

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

μƒ˜ν”Œ ν”„λ‘œμ νŠΈ

λ‹€μŒ λ§ν¬μ—μ„œ κ°„λ‹¨ν•œ ν”„λ‘œμ νŠΈ μƒ˜ν”Œμ„ λ‹€μš΄λ‘œλ“œ ν•  수 μžˆμŠ΅λ‹ˆλ‹€: https://github.com/SonarSource/sonar-scanning-examples/tree/master/sonarqube-scanner-ant

λ©€ν‹°-λͺ¨λ“ˆ ν”„λ‘œμ νŠΈ

μƒμœ„ 및 ν•˜μœ„ λͺ¨λ“ˆμ˜ ν™˜κ²½ 섀정은 μƒμœ„(parent) build.xml νŒŒμΌμ— μ„€μ •ν•΄μ•Ό ν•©λ‹ˆλ‹€:

Parent build.xml
... 
<!-- Set modules IDs -->
<property name="sonar.modules" value="module-one,module-two"/>
   
<!-- For modules, properties are inherited from the parent. They can be overridden as shown below: -->
<property name="module-one.sonar.projectName" value="Module One" />
<property name="module-one.sonar.sources" value="sources/java" />
<property name="module-one.sonar.binaries" value="target" />
<!-- Default module base directory is <curent_directory>/<module_ID>. It can be overridden if necessary -->
<property name="module-one.sonar.projectBaseDir" value="Module 1" /> 
...

디버그 둜그 ν™œμ„±ν™”

일반적인 Ant verbose μ˜΅μ…˜μ„ μ‚¬μš©ν•΄ 디버그 둜그λ₯Ό ν™œμ„±ν™” ν•  수 μžˆμŠ΅λ‹ˆλ‹€: -v

ant sonar -v

Advanced Usage

build.xml 파일 ν˜Ήμ€ command-line νŒŒλΌλ―Έν„°λ₯Ό μ‚¬μš©ν•΄ 뢄석 νŒŒλΌλ―Έν„°λ₯Ό μΆ”κ°€ μ„€μ •ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

Β© 2017-2018 Moses Kim.

λ³„λ„μ˜ 언급이 μ—†λŠ” ν•œ, 이 슀페이슀의 μ»¨ν…μΈ λŠ” ν¬λ¦¬μ—μ΄ν‹°λΈŒ 컀먼즈 μ €μž‘μžν‘œμ‹œ-λΉ„μ˜λ¦¬-λ™μΌμ‘°κ±΄λ³€κ²½ν—ˆλ½ 4.0 ꡭ제 λΌμ΄μ„ μŠ€μ— 따라 μ΄μš©ν•  수 μžˆμŠ΅λ‹ˆλ‹€.
SONARQUBEλŠ” SonarSource SA의 νŠΈλ ˆμ΄λ“œ λ§ˆν¬μž…λ‹ˆλ‹€. λͺ¨λ“  트레이트 마크 및 μ €μž‘κΆŒμ€ 각 μ†Œμœ μžμ˜ μ†Œμœ λ¬Όμž…λ‹ˆλ‹€.

::: SonarQube κ΄€λ ¨ 문의 : 이메일 :::