Analyzing with SonarQube Scanner for Ant
SQ Official Doc Link: https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+Ant
By SonarSource – GNU LGPL 3 – Issue Tracker – Sources |
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 νκ²μ μ μν©λλ€:
<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 νμΌμ μ€μ ν΄μΌ ν©λλ€:
... <!-- 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 κ΄λ ¨ λ¬Έμ : μ΄λ©μΌ :::