java/spring dynamic web project에서 SonarQube 사용법
남들은 conf db 손대거나 하던데
어쨋든 내가 성공했던 방법을 정리한다.
sonarqube와 sonarqube scanner를 설치한다.
https://www.sonarqube.org/downloads/
https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner
sonarqube는 java 1.8부터 이용 가능하기 때문에 환경변수를 1.8로 설정.
sonarqube -> bin -> 자기 컴퓨터에 해당하는 폴더 -> StartSonar.bat 더블클릭.
약간의 시간이 지나고 SonarQube is up 올라오는거 확인
다른 프로세스가 파일을 사용 중이기 때문에 프로세스가 액세스 할 수 없습니다라고 출력 시
StopNTService.bat 한번 눌러준다.
http://localhost:9000 으로 들어가 sonarQube 페이지가 나오고
결과적으로 이 웹페이지를 통해 대시보드로 결과를 받을 수 있다.
StartSonar.bat 콘솔창은 http://localhost:9000를 사용중일때는 계속 켜둬야 한다.
종료는 컨트롤 + c 후 일괄작업종료 나오면 y
검사할 프로젝트 root 상단에 sonar-project.properties 파일을 만들고
내용은
sonar.projectKey=project
# this is the name and version displayed in the SonarQube UI. Was mandatory prior to SonarQube 6.1.
sonar.projectName=project
sonar.projectVersion=1.0
# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
# Since SonarQube 4.2, this property is optional if sonar.modules is set.
# If not set, SonarQube starts looking for source code from the directory containing
# the sonar-project.properties file.
# Encoding of the source code. Default is default system encoding
#sonar.sourceEncoding=UTF-8
sonar.sources=src/kr/re/project
sonar.java.binaries=WebContent/WEB-INF/classes
projectKey, projectName은 프로젝트명
여기서 중요한건
sonar.sources 와 sonar.java.binaries 경로로
sonar.sources는 /src... 걍 controller 폴더들의 위치.
sonar.java.binaries는 class 파일들 있는곳
쉽게 Default output folder 경로?
StartSonar.bat 콘솔창이 켜져 있는 상태에서
새로운 콘솔창을 하나 더 켜고
sonar-project.properties의 위치로 이동한 후
그 위치에서 아까 설치한 sonar-scanner > bin 내부의 sonar-scanner.bat를 실행시킨다.
기다리면
EXECUTION SUCCESS 라고 출력되고
http://localhost:9000 로 들어가면
관련된 버그들이나 Vulnerabilities(취약성), code smell(심오한 문제를 일으킬 가능성이 있는 것들) 에 대한 정보가 표시된다.
걸린 에러는 ...을 누르면
하단에 설명과 해결방법이 표시된다.