-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle
More file actions
165 lines (144 loc) · 5.43 KB
/
build.gradle
File metadata and controls
165 lines (144 loc) · 5.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
plugins {
id 'java'
id 'org.springframework.boot' version '3.4.0'
id 'io.spring.dependency-management' version '1.1.6'
id 'checkstyle'
id 'jacoco'
id 'com.diffplug.spotless' version '6.25.0'
id 'org.sonarqube' version '7.2.0.6526'
}
group = 'com.project'
version = '0.0.1-SNAPSHOT'
description = 'API Mock Service'
// ============================================================================
// Coverage Exclusion Patterns (공통 제외 패턴)
// ============================================================================
def coverageExcludePackages = [
'**/config/**', // Config 클래스 제외
'**/exception/**', // Exception 클래스 제외
'**/dto/**', // DTO 클래스 제외
'**/init/**', // Mock 데이터 초기화 클래스 제외
]
// JaCoCo용 제외 패턴 (클래스 파일)
def jacocoCoverageExcludes = coverageExcludePackages + ['**/*Application.class']
// Sonar용 제외 패턴 (소스 파일)
def sonarCoverageExcludes = coverageExcludePackages.collect { it + '/*.java' } + ['**/Application.java']
java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
// Spring Boot
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
// Database
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
runtimeOnly 'com.h2database:h2'
// Lombok
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
// Test
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}
// ============================================================================
// Test
// ============================================================================
tasks.named('test') {
useJUnitPlatform()
finalizedBy jacocoTestReport, jacocoTestCoverageVerification
}
// ============================================================================
// JaCoCo (Code Coverage)
// ============================================================================
jacoco {
toolVersion = '0.8.12'
}
jacocoTestReport {
dependsOn test
reports {
xml.required = true
html.required = true
}
afterEvaluate {
classDirectories.setFrom(files(classDirectories.files.collect {
fileTree(dir: it, exclude: jacocoCoverageExcludes)
}))
}
}
jacocoTestCoverageVerification {
dependsOn jacocoTestReport
afterEvaluate {
classDirectories.setFrom(files(classDirectories.files.collect {
fileTree(dir: it, exclude: jacocoCoverageExcludes)
}))
}
violationRules {
rule {
limit {
minimum = 0.0
}
}
}
// 검사할 클래스가 없으면 커버리지 검증 건너뛰기
doFirst {
def hasClasses = classDirectories.files.any { dir ->
dir.exists() && fileTree(dir: dir, exclude: jacocoCoverageExcludes).files.size() > 0
}
if (!hasClasses) {
println "No classes to verify coverage. Skipping jacocoTestCoverageVerification."
throw new StopExecutionException()
}
}
}
// ============================================================================
// Checkstyle (Code Style) - Naver Conventions
// ============================================================================
checkstyle {
toolVersion = '10.21.4'
configFile = file("${rootDir}/config/checkstyle/checkstyle.xml")
configDirectory = file("${rootDir}/config/checkstyle")
ignoreFailures = false
maxWarnings = 0
}
// ============================================================================
// Spotless (Code Formatting) - 4-space indentation, Naver import order
// ============================================================================
spotless {
java {
target 'src/*/java/**/*.java'
googleJavaFormat().aosp().reflowLongStrings()
// Naver convention import order: java -> javax -> jakarta -> org -> net -> com -> others -> lombok
importOrder('java', 'javax', 'jakarta', 'org', 'net', 'com', '', 'lombok')
trimTrailingWhitespace()
endWithNewline()
}
}
// ============================================================================
// SonarQube (Self-Hosted)
// ============================================================================
sonar {
properties {
property 'sonar.projectKey', 'api-mock'
property 'sonar.projectName', 'api-mock'
// Java 분석을 위한 바이너리 경로
property 'sonar.java.binaries', 'build/classes/java/main'
property 'sonar.java.libraries', "${System.getProperty('user.home')}/.gradle/caches/**/modules-*/files-*/**/*.jar"
// JaCoCo 커버리지
property 'sonar.java.coveragePlugin', 'jacoco'
property 'sonar.coverage.jacoco.xmlReportPaths', 'build/reports/jacoco/test/jacocoTestReport.xml'
property 'sonar.coverage.exclusions', sonarCoverageExcludes.join(',')
}
}