java
CHAPTER 84 / 99
읽기 약 2분
FUNCTION
코드 품질: SonarQube + Checkstyle
핵심 개념
정적 분석·코드 커버리지·코딩 컨벤션 — CI 파이프라인 품질 게이트.
본문
Checkstyle (Gradle)
plugins {
id 'checkstyle'
}
checkstyle {
toolVersion = '10.12.0'
configFile = file('config/checkstyle/checkstyle.xml')
maxWarnings = 0 // 경고 0건 강제
}
// 컴파일 시 자동 실행
check.dependsOn checkstyleMain, checkstyleTest<!-- config/checkstyle/checkstyle.xml -->
<module name="Checker">
<module name="LineLength">
<property name="max" value="120"/>
</module>
<module name="TreeWalker">
<module name="Indentation">
<property name="basicOffset" value="4"/>
</module>
<module name="UnusedImports"/>
<module name="MissingJavadocMethod"/>
</module>
</module>JaCoCo — 코드 커버리지
plugins {
id 'jacoco'
}
jacoco {
toolVersion = '0.8.11'
}
jacocoTestReport {
dependsOn test
reports {
xml.required = true
html.required = true
}
}
jacocoTestCoverageVerification {
violationRules {
rule {
limit {
counter = 'LINE'
minimum = 0.80 // 80% 이상
}
limit {
counter = 'BRANCH'
minimum = 0.70
}
}
}
}
check.dependsOn jacocoTestCoverageVerificationSonarQube — 통합 정적 분석
plugins {
id 'org.sonarqube' version '4.4.1.3373'
}
sonar {
properties {
property "sonar.projectKey", "ohs-backend"
property "sonar.organization", "myorg"
property "sonar.host.url", "https://sonarcloud.io"
property "sonar.coverage.jacoco.xmlReportPaths",
"build/reports/jacoco/test/jacocoTestReport.xml"
}
}
// 실행
// ./gradlew test jacocoTestReport sonarSpotBugs
plugins {
id 'com.github.spotbugs' version '6.0.7'
}
spotbugs {
excludeFilter = file('config/spotbugs/exclude.xml')
effort = 'max'
reportLevel = 'high'
}
tasks.spotbugsMain {
reports.create('html') {
required = true
outputLocation = file("$buildDir/reports/spotbugs/main.html")
}
}CI 파이프라인 — GitHub Actions
# .github/workflows/quality.yml
name: Code Quality
on:
pull_request:
branches: [main]
jobs:
quality:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
- name: Run quality checks
run: |
./gradlew check \
checkstyleMain \
jacocoTestCoverageVerification \
spotbugsMain
- name: SonarCloud
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: ./gradlew sonar
- name: Comment on PR
if: failure()
uses: actions/github-script@v7
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '❌ 품질 게이트 실패. Checkstyle/JaCoCo/SpotBugs 확인 필요.'
})다음 챕터
CH.16 "성능 테스트: JMeter" — 부하 테스트.
AI 프롬프트
🤖 AI에게 잘 물어보는 법 — 모델·전략별 프롬프트
Claude
무료: Sonnet 4.6 / Pro $20/mo: Opus 4.6
내 Spring 코드의 코드 품질 부분을 분석해서 품질 게이트 효과와 개선 우선순위를 알려줘.
ChatGPT
무료: GPT-5.5 / Plus $20/mo: GPT-5.5 Pro
코드 품질 vs 다른 패턴 비교를 실전 사례 5개로 보여주고 SonarQube vs Codacy vs DeepSource를 알려줘.
Gemini
무료: 2.5 Flash / Pro $19.99/mo: 3.1 Pro
내 코드베이스 전체를 분석해서 코드 품질 관련 기술 부채 위치를 보고해줘.
Grok
무료: Grok 4.1 / SuperGrok $30/mo
2026년 한국 기업의 코드 품질 채택률과 한국 SI 정적 분석 도구 채택률를 솔직히 알려줘.
⭐ 이것만 기억하세요
코드 품질: SonarQube + Checkstyle는 이 3가지만 확실히 잡으세요
1.Checkstyle + JaCoCo + SpotBugs + SonarQube 4단계로 자동 품질 보장
2.코드 커버리지 80%·브랜치 70% 권장 — 단순 line만 보면 의미 없음
3.다음 챕터 CH.16에서 JMeter — 부하 테스트
공유하기
진행도 84 / 99