Pre-SonarQube ローカル検証ガイド
PRを作成する前に、ローカルでSonarQubeの品質検査を事前に実行してAzure Pipelineの失敗を防ぎます。
ワークフロー
SONAR_TOKENの発行
https://sonar2.softcamp.co.kr接続 (VPNが必要)- 右上のプロフィール →My Account → Securityタブ
- Generate Tokens→ 名前を入力 →Generate
- 発行されたトークンは安全な場所に保存してください(再確認不可)
# 환경 변수로 설정 (셸 프로파일에 추가 권장)
export SONAR_TOKEN=squ_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
export SONAR_HOST_URL=https://sonar2.softcamp.co.kr
pre-sonar.shの使い方
# 기본 실행 (전체 모듈)
./scripts/pre-sonar.sh
# 특정 모듈만 스캔
./scripts/pre-sonar.sh api
./scripts/pre-sonar.sh worker
# 토큰 직접 전달
SONAR_TOKEN=<token> ./scripts/pre-sonar.sh
スクリプト内部動作:
./gradlew test --build-cache— テスト + カバレッジレポートの生成sonar-scanner実行 —sonar-project.properties基盤分析- クオリティゲート結果ポーリング(最大5分)
- 結果出力および終了コード返却 (
0= 合格,1= 失敗)
sonar-project.properties
sonar.host.url=https://sonar2.softcamp.co.kr
sonar.projectKey=infolineage-platform
sonar.projectName=InfoLineage Platform
sonar.modules=api,worker,common
# API 모듈
api.sonar.projectKey=infolineage-api
api.sonar.sources=backend/infolineage-api/src/main
api.sonar.tests=backend/infolineage-api/src/test
api.sonar.java.binaries=backend/infolineage-api/build/classes
api.sonar.java.source=25
# Worker 모듈
worker.sonar.projectKey=infolineage-worker
worker.sonar.sources=backend/infolineage-worker/src/main
worker.sonar.tests=backend/infolineage-worker/src/test
worker.sonar.java.binaries=backend/infolineage-worker/build/classes
worker.sonar.java.source=25
SonarLint 接続モードの設定 (IntelliJ)
SonarLintをサーバーに接続すると、ローカルIDEでリアルタイム にサーバーのルール違反を確認できます。
- IntelliJ → Settings → Plugins → SonarLintインストール
- Settings → Tools → SonarLint → Connected Modeタブ
- Add connectionクリック
- Connection type:
SonarQube - Server URL:
https://sonar2.softcamp.co.kr - Authentication: Token →
SONAR_TOKEN値の入力
- Connection type:
- Project binding →
infolineage-apiまたはinfolineage-worker選択 - Update bindingクリック → サーバールールの同期
クオリティゲート基準
| 項目 | 基準 |
|---|---|
| 新しいコードカバレッジ | ≥ 80% |
| 新しいコードの重複 | ≤ 3% |
| 新しいバグ | 0 |
| 新しい脆弱性 | 0 |
| 新しいコードスメル (Major以上) | 0 |
Quality Gateは新しいコード基準です。既存のレガシーコードの未達はビルドを妨げません。
よく発生する違反パターン
| 違反 | 原因 | 修正方法 |
|---|---|---|
java:S1068 | 使用されていないプライベートフィールド | フィールドの削除または@SuppressWarnings |
java:S2696 | staticでないフィールドをstaticに修正 | フィールド設計の再検討 |
java:S3776 | メソッドの複雑度を超えました | メソッドの分離 |
java:S2259 | 潜在的なNullPointerException | Optionalまたは null チェックを追加 |
| Coverage miss | テスト未作成 | 単体テストの追加 |