-
Notifications
You must be signed in to change notification settings - Fork 30
/
build.gradle
341 lines (303 loc) · 12 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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
plugins {
id "com.dorongold.task-tree" version "2.1.1"
id 'io.freefair.lombok' version '8.6' apply false
id "com.diffplug.spotless" version '6.25.0'
id 'me.champeau.jmh' version '0.7.2' apply false
id 'jacoco'
}
allprojects {
apply plugin: 'jacoco'
repositories {
mavenCentral()
}
}
// Define version properties
ext {
// support -Dbuild.version, but include default
buildVersion = System.getProperty("build.version", "0.1.0")
// support -Dbuild.snapshot=false, but default to true
buildSnapshot = System.getProperty("build.snapshot", "true") == "true"
finalVersion = buildSnapshot ? "${buildVersion}-SNAPSHOT" : buildVersion
}
allprojects {
version = finalVersion
// This should eventually change, see https://opensearch.atlassian.net/browse/MIGRATIONS-2167
group = 'org.opensearch.migrations.trafficcapture'
tasks.withType(Jar).tap {
configureEach {
manifest {
attributes(
'SPDX-License-Identifier': 'Apache-2.0'
)
}
}
}
}
subprojects { subproject ->
subproject.afterEvaluate {
if (subproject.plugins.hasPlugin('java') && subproject.name != 'commonDependencyVersionConstraints') {
subproject.dependencies {
implementation project(":commonDependencyVersionConstraints")
annotationProcessor project(":commonDependencyVersionConstraints")
if (subproject.plugins.hasPlugin('java-test-fixtures')) {
testFixturesImplementation project(":commonDependencyVersionConstraints")
}
}
}
}
}
task buildDockerImages() {
dependsOn(':TrafficCapture:dockerSolution:buildDockerImages')
dependsOn(':DocumentsFromSnapshotMigration:buildDockerImages')
}
spotless {
format 'misc', {
target '**/*.gradle', '.gitattributes', '.gitignore'
targetExclude '**/build/**'
trimTrailingWhitespace()
indentWithSpaces()
endWithNewline()
}
yaml {
target '**/*.yml'
targetExclude '**/node_modules/**', '**/opensearch-cluster-cdk/**', '**/cdk.out/**'
trimTrailingWhitespace()
indentWithSpaces()
endWithNewline()
}
json {
target 'deployment/cdk/opensearch-service-migration/*.json'
prettier()
endWithNewline()
}
}
subprojects {
apply plugin: 'jacoco'
apply plugin: 'java'
apply plugin: 'maven-publish'
apply plugin: "com.diffplug.spotless"
// See https://github.com/diffplug/spotless/tree/main/plugin-gradle#java for some documentation,
// though what '#' does is still undocumented from what I can tell
spotless {
java {
target "**/*.java"
targetExclude '**/build/**', ".gradle/**"
importOrder(
'javax',
'java',
'org.opensearch',
'',
'\\#')
indentWithSpaces()
endWithNewline()
removeUnusedImports()
}
}
tasks.withType(Test) {
// Getting javadoc to compile is part of the test suite to ensure we are able to publish our artifacts
dependsOn project.javadoc
testLogging {
events "passed", "skipped", "failed"
exceptionFormat "full"
showExceptions true
showCauses true
showStackTraces true
}
maxParallelForks = gradle.startParameter.maxWorkerCount
// Provide way to exclude particular tests from CLI
// e.g. ../gradlew test -PexcludeTests=**/KafkaProtobufConsumerLongTermTest*
if (project.hasProperty('excludeTests')) {
exclude project.property('excludeTests')
}
useJUnitPlatform()
// Disable parallel test execution, see MIGRATIONS-1666
systemProperty 'junit.jupiter.execution.parallel.enabled', 'false'
systemProperty 'log4j2.contextSelector', 'org.apache.logging.log4j.core.selector.BasicContextSelector'
// Verify assertions in tests
jvmArgs = ['-ea', '-XX:+HeapDumpOnOutOfMemoryError']
jacoco.enabled = true
}
// Mutually exclusive tests to avoid duplication
tasks.named('test') {
systemProperty 'migrationLogLevel', 'TRACE'
useJUnitPlatform {
excludeTags('longTest', 'isolatedTest')
}
}
tasks.register('slowTest', Test) {
systemProperty 'migrationLogLevel', 'DEBUG'
useJUnitPlatform {
includeTags 'longTest'
excludeTags 'isolatedTest'
}
}
tasks.register('isolatedTest', Test) {
maxParallelForks = 1
useJUnitPlatform {
includeTags 'isolatedTest'
}
}
tasks.register('fullTest') {
dependsOn test
dependsOn slowTest
dependsOn isolatedTest
}
task javadocJar(type: Jar, dependsOn: javadoc) {
archiveClassifier.set('javadoc')
from javadoc.destinationDir
}
task sourcesJar(type: Jar) {
archiveClassifier.set('sources')
from sourceSets.main.allSource
duplicatesStrategy = DuplicatesStrategy.WARN
}
def excludedProjectPaths = [
':RFS',
':TrafficCapture',
':TrafficCapture:dockerSolution',
]
if (!(project.path in excludedProjectPaths)) {
publishing {
publications {
mavenJava(MavenPublication) {
versionMapping {
allVariants {
// Test fixtures are published as a separate jar in maven
// This ensures dependencies that are only declared in test
// fixtures have a version number in the pom
if (project.plugins.hasPlugin('java-test-fixtures')) {
fromResolutionOf('testFixturesRuntimeClasspath')
}
fromResolutionResult()
}
}
from components.java
artifact javadocJar
artifact sourcesJar
pom {
name = project.name
description = 'Everything opensearch migrations'
url = 'http://github.com/opensearch-project/opensearch-migrations'
licenses {
license {
name = 'The Apache License, Version 2.0'
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
developers {
developer {
name = "OpenSearch"
url = "https://github.com/opensearch-project/opensearch-migrations"
}
}
scm {
connection = "scm:[email protected]:opensearch-project/opensearch-migrations.git"
developerConnection = "scm:[email protected]:opensearch-project/opensearch-migrations.git"
url = "[email protected]:opensearch-project/opensearch-migrations.git"
}
}
pom.withXml {
def pomFile = asNode()
// Find all dependencies in the POM file
def dependencies = pomFile.dependencies.dependency
// Iterate over each dependency and check if the version is missing
dependencies.each { dependency ->
def version = dependency.version.text()
if (version == null || version.trim().isEmpty() || version.trim() == 'unspecified') {
def groupId = dependency.groupId.text()
def artifactId = dependency.artifactId.text()
throw new GradleException("Dependency ${groupId}:${artifactId} is missing a version in the pom.xml")
}
}
}
// Suppress POM metadata warnings for test fixtures
suppressPomMetadataWarningsFor('testFixturesApiElements')
suppressPomMetadataWarningsFor('testFixturesRuntimeElements')
}
}
repositories {
maven { url = "${rootProject.buildDir}/repository"}
maven {
url "https://aws.oss.sonatype.org/content/repositories/snapshots"
name = 'staging'
}
}
}
}
// Utility task to allow copying required libraries into a 'dependencies' folder for security scanning
tasks.register('copyDependencies', Sync) {
duplicatesStrategy = DuplicatesStrategy.WARN
from configurations.runtimeClasspath
into "${buildDir}/dependencies"
}
jacocoTestReport {
dependsOn = project.tasks.withType(Test).matching { it.jacoco && it.jacoco.enabled }
executionData.from = project.tasks.withType(Test).matching { it.jacoco && it.jacoco.enabled }.collect { it.jacoco.destinationFile }
classDirectories.from = files(subprojects.collect { it.sourceSets.main.output.classesDirs })
reports {
xml.required = true
xml.destination file("${buildDir}/reports/jacoco/test/jacocoTestReport.xml")
html.required = true
html.destination file("${buildDir}/reports/jacoco/test/html")
}
}
}
gradle.projectsEvaluated {
List<Task> isolatedTestsTasks = []
List<Task> sharedProcessTestsTasks = []
subprojects { subproject ->
subproject.tasks.withType(Test).all { task ->
if (task.name == "isolatedTest") {
isolatedTestsTasks.add(task)
} else {
sharedProcessTestsTasks.add(task)
}
}
}
isolatedTestsTasks.sort { task -> task.project.name }
// Create a sequential dependency chain
Task previousTask = null
isolatedTestsTasks.each { task ->
sharedProcessTestsTasks.forEach {task.mustRunAfter(it) }
if (previousTask != null) {
task.mustRunAfter(previousTask)
}
previousTask = task
}
tasks.register("allTests") {
dependsOn sharedProcessTestsTasks
dependsOn isolatedTestsTasks
}
}
task mergeJacocoReports(type: JacocoReport) {
def jacocoReportTasks = subprojects.collect { it.tasks.withType(JacocoReport).matching { it.name == "jacocoTestReport" } }.flatten()
dependsOn jacocoReportTasks
additionalSourceDirs.setFrom(files(jacocoReportTasks.collect { it.additionalSourceDirs }.flatten()))
sourceDirectories.setFrom(files(jacocoReportTasks.collect { it.sourceDirectories }.flatten()))
classDirectories.setFrom(files(subprojects.collect { subproject ->
subproject.sourceSets.main.output.classesDirs.filter { dir ->
!dir.path.contains('captureProtobufs') && !dir.path.contains('trafficCaptureProxyServerTest')
}
}))
executionData.setFrom(files(jacocoReportTasks.collect { it.executionData }.flatten()))
reports {
xml.required = true
xml.destination = file("${buildDir}/reports/jacoco/mergedReport/jacocoMergedReport.xml")
html.required = true
html.destination = file("${buildDir}/reports/jacoco/mergedReport/html")
}
}
task listPublishedArtifacts {
doLast {
subprojects.each { proj ->
def publishingExtension = proj.extensions.findByType(PublishingExtension)
if (publishingExtension) {
publishingExtension.publications.each { publication ->
if (publication instanceof MavenPublication) {
println "${publication.groupId}.${publication.artifactId}"
}
}
}
}
}
}