forked from arunx2/opensearch-migrations
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
237 lines (210 loc) · 8.33 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
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()
}
}
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()
}
}
subprojects {
apply plugin: 'jacoco'
apply plugin: 'java'
apply plugin: 'maven-publish'
apply plugin: "com.diffplug.spotless"
spotless {
java {
target "**/*.java"
targetExclude '**/build/**', ".gradle/**"
importOrder(
'java|javax',
'io.opentelemetry|com.google|com.fasterxml|org.apache|org.hamcrest|org.junit',
'org.opensearch',
'',
'\\#java|\\#org.apache|\\#org.hamcrest|\\#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
showStandardStreams = true
}
// 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'
}
// Mutually exclusive tests to avoid duplication
tasks.named('test') {
useJUnitPlatform {
excludeTags 'longTest'
}
jacoco.enabled = true
}
tasks.register('slowTest', Test) {
useJUnitPlatform {
includeTags 'longTest'
}
jacoco.enabled = true
}
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.EXCLUDE
}
def excludedProjectPaths = [
':RFS',
':TrafficCapture',
':TrafficCapture:dockerSolution',
]
if (!(project.path in excludedProjectPaths)) {
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
artifact javadocJar
artifact sourcesJar
group = 'org.opensearch.migrations.trafficcapture'
// support -Dbuild.version, but include default
version = System.getProperty("build.version", "0.1.0")
// support -Dbuild.snapshot=false, but default to true
if (System.getProperty("build.snapshot", "true") == "true") {
version += "-SNAPSHOT"
}
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:git@github.com:opensearch-project/opensearch-migrations.git"
developerConnection = "scm:git@github.com:opensearch-project/opensearch-migrations.git"
url = "git@github.com:opensearch-project/opensearch-migrations.git"
}
}
// 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.EXCLUDE
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 }
// Exclude protos and load tests from test coverage
classDirectories.from = files(subprojects.collect { it.sourceSets.main.output.collect {
fileTree(dir: it) {
exclude '**/protos/**'
exclude '**/JMeterLoadTest**'
}
} })
reports {
xml.required = true
xml.destination file("${buildDir}/reports/jacoco/test/jacocoTestReport.xml")
html.required = true
html.destination file("${buildDir}/reports/jacoco/test/html")
}
}
}
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}"
}
}
}
}
}
}