-
Notifications
You must be signed in to change notification settings - Fork 121
/
Copy pathbuild.gradle
237 lines (202 loc) · 8.18 KB
/
build.gradle
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
import org.jsoup.Jsoup
import org.jsoup.nodes.Element
import org.jsoup.select.Elements
import static java.lang.Math.min
buildscript {
dependencies {
classpath libs.jsoup
}
}
plugins {
alias libs.plugins.nexus.publish
alias libs.plugins.osdetector apply false
}
allprojects {
repositories {
mavenCentral()
}
}
ext {
// Remove 'java' from the client artifact IDs.
artifactIdOverrides = [
':client:java': "${rootProject.name}-client",
':client:java-armeria': "${rootProject.name}-client-armeria",
':client:java-armeria-legacy': "${rootProject.name}-client-armeria-legacy",
':client:java-spring-boot2-autoconfigure': "${rootProject.name}-client-spring-boot2-autoconfigure",
':client:java-spring-boot2-starter': "${rootProject.name}-client-spring-boot2-starter",
':client:java-spring-boot3-autoconfigure': "${rootProject.name}-client-spring-boot3-autoconfigure",
':client:java-spring-boot3-starter': "${rootProject.name}-client-spring-boot3-starter",
// Set the correct artifactId of 'testing-common'.
':testing:testing-common': "${rootProject.name}-testing-common"
]
}
apply from: "${rootDir}/gradle/scripts/build-flags.gradle"
configure(projectsWithFlags('java')) {
// Common properties and functions.
ext {
thriftVersion = '0.9'
}
dependencies {
// All projects currently require ':common' (except itself)
if (project.name != 'common') {
api project(':common')
}
// Testing utilities
testImplementation project(':testing-internal')
// completable-futures
implementation libs.futures.completable
// cron-utils
implementation libs.cron.utils
// Guava
implementation libs.guava
// Jackson
implementation libs.jackson.annotations
implementation libs.jackson.core
implementation libs.jackson.databind
// javax.inject
api libs.javax.inject
// JSR305
implementation libs.findbugs
// Jetty ALPN support
compileOnly libs.jetty.alpn.api
// Logging
if (project.name.startsWith("java-spring-boot3")) {
implementation libs.slf4j2.api
testImplementation libs.slf4j2.jul.to.slf4j
testImplementation libs.slf4j2.jcl.over.slf4j
testImplementation libs.slf4j2.log4j.over.slf4j
testRuntimeOnly libs.logback15
configurations.configureEach {
resolutionStrategy {
force libs.slf4j2.api.get()
force libs.slf4j2.jul.to.slf4j.get()
force libs.slf4j2.jcl.over.slf4j.get()
force libs.slf4j2.log4j.over.slf4j.get()
force libs.logback15.get()
}
}
} else {
implementation libs.slf4j1.api
testImplementation libs.slf4j1.jul.to.slf4j
testImplementation libs.slf4j1.jcl.over.slf4j
testImplementation libs.slf4j1.log4j.over.slf4j
testRuntimeOnly libs.logback12
}
// Test-time dependencies
testImplementation libs.json.unit.fluent
testImplementation libs.awaitility
testImplementation libs.hamcrest.library
testImplementation libs.assertj
testImplementation libs.mockito.core
testImplementation libs.mockito.junit.jupiter
testImplementation libs.junit5.jupiter.api
testImplementation libs.junit5.jupiter.params
testRuntimeOnly libs.junit5.jupiter.engine
testRuntimeOnly libs.junit5.platform.launcher
testRuntimeOnly libs.junit5.vintage.engine
}
// Target Java 8 except for spring-boot3
if (!project.name.startsWith("java-spring-boot3")) {
tasks.withType(JavaCompile) {
if (JavaVersion.current() >= JavaVersion.VERSION_1_9) {
options.release = 8
}
}
}
// Add common JVM options such as max memory and leak detection.
tasks.withType(JavaForkOptions) {
// Use larger heap when test coverage is enabled.
maxHeapSize = hasFlags('coverage') ? '512m' : '384m'
// Enable leak detection when '-Pleak' option is specified.
if (project.hasProperty('leak')) {
systemProperties 'io.netty.leakDetectionLevel': 'paranoid'
}
}
tasks.sourcesJar.duplicatesStrategy = DuplicatesStrategy.INCLUDE
tasks.processResources.duplicatesStrategy = DuplicatesStrategy.INCLUDE
}
tasks.register("reportFailedTests", TestsReportTask)
/**
* Summarizes the failed tests and reports as a file with the Markdown syntax.
*/
class TestsReportTask extends DefaultTask {
@OutputFile
final def reportFile = project.file("${project.buildDir}/failed-tests-result.txt")
@TaskAction
def run() {
// Collect up to 20 error results
int maxErrorSize = 20
List<Map> failedTests = []
Set<String> handledFiles = []
project.allprojects {
tasks.withType(Test) { testTask ->
def xmlFiles = testTask.reports.junitXml.outputLocation.asFileTree.files
if (xmlFiles.isEmpty()) {
return
}
xmlFiles.each { file ->
if (!handledFiles.add(file.name)) {
return
}
Elements failures = Jsoup.parse(file, 'UTF-8').select("testsuite failure")
if (failures.isEmpty() || failedTests.size() > maxErrorSize) {
return
}
failures.each { failure ->
Element parent = failure.parent()
String fullMethodName = "${parent.attr("classname")}.${parent.attr("name")}"
String detail = failure.wholeText()
failedTests += [method: fullMethodName, detail: detail]
}
}
}
}
if (failedTests.isEmpty()) {
return
}
reportFile.withPrintWriter('UTF-8') { writer ->
failedTests.each { it ->
String method = it.method
String detail = it.detail
// Create an link to directly create an issue from the error message
String ghIssueTitle = URLEncoder.encode("Test failure: `$method`", "UTF-8")
// 8k is the maximum allowed URL length for GitHub
String ghIssueBody = URLEncoder.encode(
"```\n${detail.substring(0, min(6000, detail.length()))}\n```\n", "UTF-8")
String ghIssueLink =
"https://github.com/line/centraldogma/issues/new?title=$ghIssueTitle&body=$ghIssueBody"
String ghSearchQuery = URLEncoder.encode("is:issue $method", "UTF-8")
String ghSearchLink = "https://github.com/line/centraldogma/issues?q=$ghSearchQuery"
writer.print("- $it.method - [Search similar issues]($ghSearchLink) | ")
writer.println("[Create an issue?]($ghIssueLink)")
writer.println(" ```")
List<String> lines = detail.split("\n") as List
def summary = lines.take(8)
summary.each { line -> writer.println(" $line") }
writer.println(" ```")
if (lines.size() > 8) {
writer.println(" <details><summary>Full error messages</summary>")
writer.println(" <pre>")
lines.each { line -> writer.println(" $line") }
writer.println(" </pre></details>\n")
}
}
}
}
}
// Configure the Javadoc tasks of all projects.
allprojects {
tasks.withType(Javadoc) {
options {
// Exclude the machine-generated or internal-only classes
exclude '**/internal/**'
exclude '**/thrift/**'
}
}
}
// Require to use JDK 21 when releasing.
tasks.release.doFirst {
if (JavaVersion.current() != JavaVersion.VERSION_21) {
throw new IllegalStateException("You must release using JDK 21. Current: ${JavaVersion.current()}")
}
}