[SonarQube] 오픈소스 정적분석 Tool 소나큐브 사용법

2024. 9. 19. 17:41·etc/오픈소스 라이브러리

소나큐브란?


소나큐브는 프로그래밍 언어에서 버그, 코드 스멜, 보안 취약점 등을 발견하기 위한 정적 코드 분석 툴이다. 

설치 / 세팅


1. 소나큐브 설치

https://www.sonarsource.com/products/sonarqube/downloads/

 

Download | SonarQube

Get the latest LTS and version of SonarQube the leading product for Code Quality and Security from the official download page.

www.sonarsource.com

 

2. 소나큐브 실행

  • 다운로드 파일 압축 풀기
  • 소나큐브 실행
    • Window: /bin/windows-x86-64/StartSonar.bat 실행
    • Linux: /bin/linux-x86-64/sh sonar.sh 실행

(Linux 명령어)

sh sonar.sh start

 

실행되는데 1분 이상 걸리는 듯하다.

 

(3. Java 11 설치)

잘 동작하지 않는다면 Java 11 이상을 설치 후 JAVA_HOME 환경변수를 세팅해 주자.

 

4. 로그인

접속: localhost:9000

 

정상적으로 실행되었다면 로그인 창이 뜰 것이다.

기본 ID/PW는 admin/admin이다.

 

(소나큐브 설치 - Docker)

docker 설치 후 아래 명령어 입력

# 실행중인 프로세스 조회
docker ps

CONTAINER ID   IMAGE       ...   PORTS
xxxxxxxxxxxx   sonarqube   ...   0.0.0.0:9000->9000/tcp

# 기존 프로세스 stop 및 제거
docker stop sonarqube
docker rm sonarqube
docker run -d --name sonarqube -p 9000:9000 sonarqube

 

 

SonarQube 프로젝트생성


1. 프로젝트 생성 

Create a local project 선택

 

2. 로컬 프로젝트 생성

name, key는 단지 SonarQube에서 프로젝트를 식별하기 위한 key이다.

기본 세팅 선택

 

소스코드 분석


1. 분석 세팅

1) 로컬 프로젝트 Locally 선택

2) 토큰 생성

3) 명령어 생성

아래와 같이 명령어를 생성해준다.

명령어를 복사해서 pom.xml, build.gradle 등 빌드 파일이 위치한 곳에서 명령어를 실행하면 된다.


2. 분석 실행

리눅스 쉘을 통해 프로젝트 루트 디렉터리로 이동한다.

위에서 제공된 명령어를 복사해서 pom.xml이 위치하는 루트 디렉터리에서 실행시킨다.


3. 분석 결과

SonarQube가 실행되고 있는 localhost:9000에서 분석 결과를 확인할 수 있다.

 

4. 다중모듈 프로젝트 분석

기본적으로 SonarQube는 특정 디렉터리의 하위 디렉터리만 분석할 수 있다. 따라서 다중모듈 프로젝트를 분석하려는 경우 최상단 디렉터리에 아래와 같이 파일을 추가해줘야한다.

 

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project>
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example</groupId>
    <artifactId>parent-project</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>pom</packaging>

    <modules>
        <module>management</module>
        <module>core</module>
        <module>public</module>
    </modules>
</project>
반응형
저작자표시 (새창열림)

'etc > 오픈소스 라이브러리' 카테고리의 다른 글

[Java / Playground] Rest API 호출 모듈 만들기 / RestTemplate  (0) 2024.12.15
[java/Playground] Apache POI 엑셀 파일 다루기  (0) 2024.09.04
[Apache POI] Java 코드로 엑셀(.xlsx) 파일 생성하기 - Java로 Excel 다루기  (0) 2024.07.18
[SchemaSpy] DB 스키마 분석, 시각화 Tool 사용 방법  (1) 2024.07.02
'etc/오픈소스 라이브러리' 카테고리의 다른 글
  • [Java / Playground] Rest API 호출 모듈 만들기 / RestTemplate
  • [java/Playground] Apache POI 엑셀 파일 다루기
  • [Apache POI] Java 코드로 엑셀(.xlsx) 파일 생성하기 - Java로 Excel 다루기
  • [SchemaSpy] DB 스키마 분석, 시각화 Tool 사용 방법
HSRyuuu
HSRyuuu
Web Server Developer hsryuuu
  • HSRyuuu
    HS_dev_log
    HSRyuuu
  • 전체
    오늘
    어제
  • 링크

    • Github
    • 전체 글 보기 (251)
      • Spring (37)
      • Infra & DevOps (20)
      • Java (25)
      • AI (8)
      • Database (28)
      • Web & Network (14)
      • 자료구조 & 알고리즘 (30)
      • Computer Science (24)
      • Frontend (17)
        • Vue.js & Nuxt.js (9)
        • JSP_Thymeleaf (7)
      • etc (48)
        • 오픈소스 라이브러리 (5)
        • 코딩테스트 (13)
        • Trouble Shooting (7)
        • Tech Interview (6)
        • Book Review (9)
        • 끄적끄적... (6)
        • 개인 프로젝트 (2)
  • 태그

    Database
    Redisson
    SpringBoot
    HTTP
    리눅스
    백엔드기술면접
    개발자
    Nuxt3
    트랜잭션
    백준
    Queue
    JPA
    mybatis
    Redis
    Linux
    백엔드스쿨
    cleancode
    자료구조
    기술면접
    백엔드공부
    백엔드
    docker
    web
    TechInterview
    Java
    SQL
    제로베이스
    Spring
    클린코드
    MySQL
  • 블로그 메뉴

    • 홈
    • 태그
  • hELLO· Designed By정상우.v4.10.4
HSRyuuu
[SonarQube] 오픈소스 정적분석 Tool 소나큐브 사용법
상단으로

티스토리툴바