-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild.gradle
More file actions
214 lines (172 loc) · 5.83 KB
/
Copy pathbuild.gradle
File metadata and controls
214 lines (172 loc) · 5.83 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
plugins {
id 'java'
id 'org.springframework.boot' version '3.4.2'
id 'io.spring.dependency-management' version '1.1.7'
id 'jacoco'
id 'com.diffplug.spotless' version '6.25.0'
id "org.sonarqube" version "4.4.1.3373"
}
group = 'io.crops'
version = '0.0.1-SNAPSHOT'
java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
// JPA
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
// Redis
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
// Security
implementation 'org.springframework.boot:spring-boot-starter-security'
// JWT
implementation 'io.jsonwebtoken:jjwt-api:0.11.5'
implementation 'io.jsonwebtoken:jjwt-impl:0.11.5'
implementation 'io.jsonwebtoken:jjwt-jackson:0.11.5'
// Validation
implementation 'org.springframework.boot:spring-boot-starter-validation'
// Web
implementation 'org.springframework.boot:spring-boot-starter-web'
// Websocket
implementation 'org.springframework.boot:spring-boot-starter-websocket'
// Oauth
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'
// Lombok
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
// H2
runtimeOnly 'com.h2database:h2'
// Mysql
runtimeOnly 'com.mysql:mysql-connector-j'
// Jackson Java 8에서 도입된 날짜와 시간 API(JSR-310)를 JSON으로 직렬화/역직렬화
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310'
//Querydsl
implementation 'com.querydsl:querydsl-jpa:5.0.0:jakarta'
annotationProcessor "com.querydsl:querydsl-apt:${dependencyManagement.importedProperties['querydsl.version']}:jakarta"
annotationProcessor "jakarta.annotation:jakarta.annotation-api"
annotationProcessor "jakarta.persistence:jakarta.persistence-api"
// Test
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
// Swagger
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.8.0'
implementation 'org.ahocorasick:ahocorasick:0.6.3'
}
tasks.named('test') {
useJUnitPlatform()
}
// Querydsl 설정부
def generated = 'src/main/generated'
// querydsl QClass 파일 생성 위치를 지정
tasks.withType(JavaCompile) {
options.getGeneratedSourceOutputDirectory().set(file(generated))
}
// java source set 에 querydsl QClass 위치 추가
sourceSets {
main.java.srcDirs += [ generated ]
}
// gradle clean 시에 QClass 디렉토리 삭제
clean {
delete file(generated)
}
// Jacoco 설정
jacoco {
toolVersion = '0.8.11'
}
// 공통 exclude 패턴을 상단에 정의
def excludePatterns = [
'**/Q*.class',
'**/*Application.class',
'**/dto/**',
'**/global/**',
'**/repository/**',
]
jacocoTestReport {
reports {
xml.required = true
csv.required = false
html.required = true
html.outputLocation = layout.buildDirectory.dir('jacocoHtml')
}
afterEvaluate {
classDirectories.setFrom(files(classDirectories.files.collect {
fileTree(dir: it, excludes: excludePatterns)
}))
}
finalizedBy 'jacocoTestCoverageVerification'
}
jacocoTestCoverageVerification {
violationRules {
rule {
element = 'CLASS'
// 코드의 모든 조건부 분기가 테스트되었는지를 측정
limit {
counter = 'BRANCH'
value = 'COVEREDRATIO'
minimum = 0.8
}
// 테스트 코드가 실제 프로덕션 코드의 각 라인을 얼마나 실행했는지를 측정
limit {
counter = 'LINE'
value = 'COVEREDRATIO'
minimum = 0.6
}
excludes = excludePatterns
}
}
afterEvaluate {
classDirectories.setFrom(files(classDirectories.files.collect {
fileTree(dir: it, excludes: excludePatterns)
}))
}
}
// Spotless 설정
spotless {
java {
target {
project.files(
"src/main/java/**/*.java",
"src/test/java/**/*.java"
)
}
importOrder() // import 문 정렬
removeUnusedImports() // 사용하지 않는 import 제거
googleJavaFormat().aosp() // Google Java 스타일 가이드 적용, aosp 4칸 들여쓰기
formatAnnotations() // 어노테이션 포맷팅
}
}
// 의존성 순서 설정
spotlessJava.dependsOn compileJava
build.dependsOn spotlessApply
// test 실행 후 Jacoco 리포트 생성
test {
finalizedBy jacocoTestReport
}
// SonarQube 설정
sonar {
properties {
property "sonar.projectKey", "prgrms-web-devcourse-final-project_WEB2_3_9crops_BE"
property "sonar.organization", "prgrms-web-devcourse-final-project"
property "sonar.host.url", "https://sonarcloud.io"
property "sonar.sources", "src/main/java"
property "sonar.tests", "src/test/java"
property "sonar.java.binaries", "${buildDir}/classes"
property "sonar.coverage.jacoco.xmlReportPaths", "${buildDir}/reports/jacoco/test/jacocoTestReport.xml"
property "sonar.security.hotspots.suppressions", "java:S4834" // CSRF 비활성화 경고 무시
property "sonar.coverage.exclusions", excludePatterns.collect {
it.replace('.class', '.java') // class 확장자를 java로 변경
}.join(',')
}
}
// test와 jacocoTestReport를 sonar 전에 실행하도록 설정
tasks.sonar.dependsOn test, jacocoTestReport