-
Notifications
You must be signed in to change notification settings - Fork 59
/
build.gradle
387 lines (340 loc) · 13.3 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
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/
import java.nio.file.Files
import org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestFramework
import org.opensearch.gradle.test.RestIntegTestTask
import org.opensearch.gradle.testclusters.ExtensionsProperties
buildscript {
ext {
opensearch_version = System.getProperty("opensearch.version", "3.0.0")
isSnapshot = "true" == System.getProperty("build.snapshot", "true")
if (isSnapshot) {
opensearch_version += "-SNAPSHOT"
}
buildVersionQualifier = System.getProperty("build.version_qualifier", "")
}
repositories {
mavenLocal()
mavenCentral()
maven { url "https://aws.oss.sonatype.org/content/repositories/snapshots" }
}
dependencies {
classpath "org.opensearch.gradle:build-tools:${opensearch_version}"
}
}
plugins {
id 'java-library'
id "com.diffplug.spotless" version "6.25.0" apply false
id 'jacoco'
id "com.form.diff-coverage" version "0.9.5"
// for javadocs and checks spotless doesn't do
id 'checkstyle'
}
apply from: 'gradle/formatting.gradle'
apply plugin: 'java'
apply plugin: 'opensearch.opensearchplugin'
apply plugin: 'opensearch.testclusters'
opensearchplugin {
name 'opensearch-sdk-java'
description 'OpenSearch Software Development Kit'
classname 'org.opensearch.sdk.sample.helloworld.HelloWorldExtension'
}
ext {
projectSubstitutions = [:]
licenseFile = rootProject.file('LICENSE.txt')
noticeFile = rootProject.file('NOTICE.txt')
}
dependencyLicenses.enabled = false
thirdPartyAudit.enabled = false
loggerUsageCheck.enabled = false
forbiddenApisMain.enabled = false
forbiddenApisTest.enabled = false
filepermissions.enabled = false
forbiddenPatterns.enabled = false
testingConventions.enabled = false
validateNebulaPom.enabled = false
def _numNodes = findProperty('numNodes') as Integer ?: 1
def testPort = 4500
allprojects {
project.ext.licenseName = 'The Apache Software License, Version 2.0'
project.ext.licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
group = 'org.opensearch'
version = '2.0.0'
if (buildVersionQualifier) {
version += "-${buildVersionQualifier}"
}
if (isSnapshot) {
version += "-SNAPSHOT"
}
}
group 'org.opensearch.sdk'
allprojects {
// Default to the apache license
project.ext.licenseName = 'The Apache Software License, Version 2.0'
project.ext.licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
publishing {
publications {
// add license information to generated poms
all {
pom {
name = "opensearch-sdk-java"
}
pom.withXml { XmlProvider xml ->
Node node = xml.asNode()
node.appendNode('description', 'OpenSearch Java SDK Client')
Node license = node.appendNode('licenses').appendNode('license')
license.appendNode('name', project.licenseName)
license.appendNode('url', project.licenseUrl)
Node developer = node.appendNode('developers').appendNode('developer')
developer.appendNode('name', 'OpenSearch')
developer.appendNode('url', 'https://github.com/opensearch-project/opensearch-sdk-java')
}
}
}
}
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
repositories {
if (version.toString().endsWith("SNAPSHOT")) {
maven {
name = "Snapshots" // optional target repository name
url = "https://aws.oss.sonatype.org/content/repositories/snapshots"
credentials {
username "$System.env.SONATYPE_USERNAME"
password "$System.env.SONATYPE_PASSWORD"
}
}
}
maven {
name = "localRepo"
url = "$buildDir/localRepo"
}
}
}
tasks.named("publishMavenJavaPublicationToMavenLocal").configure { dependsOn("generatePomFileForNebulaPublication") }
tasks.named("publishNebulaPublicationToMavenLocal").configure { dependsOn("generatePomFileForMavenJavaPublication") }
validateMavenJavaPom.enabled = false
javadoc {
source = sourceSets.main.allJava
classpath = sourceSets.main.compileClasspath
}
repositories {
mavenLocal()
mavenCentral()
maven { url "https://aws.oss.sonatype.org/content/repositories/snapshots" }
maven { url "https://ci.opensearch.org/ci/dbc/snapshots/lucene/"}
}
dependencies {
def opensearchVersion = "${opensearch_version}"
def log4jVersion = "2.24.1"
def nettyVersion = "4.1.101.Final"
def jacksonDatabindVersion = "2.18.0"
def guavaVersion = "32.1.3-jre"
def guiceVersion = "7.0.0"
def junit4Version = "4.13.2"
def junit5Version = "5.11.2"
def junitPlatform = "1.11.2"
def jaxbVersion = "2.3.1"
def jakartaVersion = "2.1.3"
def jakartaInjectVersion = "2.0.1"
def javaxVersion = "1"
def guavaFailureAccessVersion = "1.0.2"
def aopallianceVersion = "1.0"
def slf4jVersion = "2.0.13"
def commonsLoggingVersion = "1.3.4"
api("org.opensearch:opensearch:${opensearchVersion}")
implementation("org.apache.logging.log4j:log4j-api:${log4jVersion}")
implementation("org.apache.logging.log4j:log4j-core:${log4jVersion}")
implementation("org.apache.logging.log4j:log4j-jul:${log4jVersion}")
implementation("org.opensearch.client:opensearch-rest-high-level-client:${opensearchVersion}")
api("org.opensearch.client:opensearch-rest-client:${opensearchVersion}")
api("org.opensearch.client:opensearch-java:${opensearchVersion}") {
exclude group : 'org.apache.httpcomponents.core5'
exclude group : 'org.apache.httpcomponents.client5'
}
implementation("org.opensearch.plugin:transport-netty4-client:${opensearchVersion}")
implementation("io.netty:netty-all:${nettyVersion}")
implementation("jakarta.inject:jakarta.inject-api:${jakartaInjectVersion}")
testCompileOnly("junit:junit:${junit4Version}") {
exclude module : 'hamcrest'
exclude module : 'hamcrest-core'
}
implementation("javax.xml.bind:jaxb-api:${jaxbVersion}")
implementation("com.fasterxml.jackson.core:jackson-databind:${jacksonDatabindVersion}")
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:${jacksonDatabindVersion}")
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:${jacksonDatabindVersion}")
implementation("com.fasterxml.jackson.datatype:jackson-datatype-guava:${jacksonDatabindVersion}")
implementation("com.fasterxml.jackson.core:jackson-annotations:${jacksonDatabindVersion}")
implementation("com.google.guava:guava:${guavaVersion}")
implementation("javax.inject:javax.inject:${javaxVersion}")
implementation("com.google.guava:failureaccess:${guavaFailureAccessVersion}")
implementation("aopalliance:aopalliance:${aopallianceVersion}")
constraints {
implementation("com.google.guava:guava:${guavaVersion}") {
because 'versions below 30.0 have active CVE'
}
}
implementation("com.google.inject:guice:${guiceVersion}")
testImplementation("org.junit.jupiter:junit-jupiter-api:${junit5Version}")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${junit5Version}")
testImplementation("org.opensearch.test:framework:${opensearchVersion}")
testRuntimeOnly("org.junit.platform:junit-platform-launcher:${junitPlatform}")
configurations.all {
resolutionStrategy {
force("jakarta.json:jakarta.json-api:${jakartaVersion}")
force("com.fasterxml.jackson.core:jackson-databind:${jacksonDatabindVersion}")
force("com.fasterxml.jackson.core:jackson-core:${jacksonDatabindVersion}")
force("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:${jacksonDatabindVersion}")
force("com.fasterxml.jackson.dataformat:jackson-dataformat-smile:${jacksonDatabindVersion}")
force("com.fasterxml.jackson.dataformat:jackson-dataformat-cbor:${jacksonDatabindVersion}")
force("org.apache.logging.log4j:log4j-api:${log4jVersion}")
force("org.apache.logging.log4j:log4j-core:${log4jVersion}")
force("org.apache.logging.log4j:log4j-jul:${log4jVersion}")
force("org.slf4j:slf4j-api:${slf4jVersion}")
force("commons-logging:commons-logging:${commonsLoggingVersion}")
}
}
}
// Compile SDK 2.x for JDK 21
tasks.withType(JavaCompile) {
options.release.set(21)
}
// this task runs the helloworld sample extension
task helloWorld(type: JavaExec) {
group = 'Execution'
description = 'Run HelloWorld Extension.'
mainClass = 'org.opensearch.sdk.sample.helloworld.HelloWorldExtension'
classpath = sourceSets.main.runtimeClasspath
systemProperty 'log4j2.configurationFile', 'log4j2-sdk.xml'
}
task getVersion() {
doLast {
println("version=${version}")
}
}
test {
useJUnitPlatform()
jvmArgs '--enable-preview'
systemProperty 'tests.security.manager', 'false'
testLogging {
events "passed", "skipped", "failed"
exceptionFormat "full"
}
jacoco {
classDumpDir = file("$buildDir/jacoco/classpathdumps")
}
finalizedBy jacocoTestReport
}
jacocoTestReport {
dependsOn test
reports {
xml.required = true
}
}
// Get uncommitted files via git diff
// https://github.com/form-com/diff-coverage-gradle/issues/73
ext.createDiffFile = { ->
def file = Files.createTempFile(URLEncoder.encode(project.name, 'UTF-8'), '.diff').toFile()
def diffBase = 'refs/remotes/origin/main'
// Only run locally
if (!System.getenv('CI')) {
file.withOutputStream { out ->
exec {
commandLine 'git', 'diff', '--no-color', '--minimal', diffBase
standardOutput = out
}
}
}
return file
}
diffCoverageReport {
afterEvaluate {
diffSource.file = createDiffFile()
}
// View report at build/reports/jacoco/diffCoverage/html/index.html
reports {
html = true
}
violationRules {
minBranches = 0.60
minLines = 0.75
failOnViolation = true
}
}
task integTest(type: RestIntegTestTask) {
description = "Run tests against a cluster"
testClassesDirs = sourceSets.test.output.classesDirs
classpath = sourceSets.test.runtimeClasspath
}
tasks.named("check").configure { dependsOn(integTest) }
task startTestExtension {
doFirst{
ext.process = new ProcessBuilder()
.directory(projectDir)
.command("./gradlew", "helloWorld")
.start()
}
}
integTest {
dependsOn(startTestExtension)
//TODO: find a way to add permissions for the tests
systemProperty 'tests.security.manager', 'false'
systemProperty "https", System.getProperty("https")
systemProperty "user", System.getProperty("user")
systemProperty "password", System.getProperty("password")
// The 'doFirst' delays till execution time.
doFirst {
// Tell the test JVM if the cluster JVM is running under a debugger so that tests can
// use longer timeouts for requests.
def isDebuggingCluster = getDebug() || System.getProperty("test.debug") != null
systemProperty 'cluster.debug', isDebuggingCluster
// Set number of nodes system property to be used in tests
systemProperty 'cluster.number_of_nodes', "1"
// There seems to be an issue when running multi node run or integ tasks with unicast_hosts
// not being written, the waitForAllConditions ensures it's written
getClusters().forEach { cluster ->
cluster.waitForAllConditions()
}
}
// The --debug-jvm command-line option makes the cluster debuggable; this makes the tests debuggable
if (System.getProperty("test.debug") != null) {
jvmArgs '-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005'
}
}
task closeTestExtension {
doFirst {
if (tasks.startTestExtension.process != null) {
tasks.startTestExtension.process.destroy()
}
}
}
tasks.named("integTest").configure { finalizedBy(closeTestExtension) }
testClusters.integTest {
extension(true)
testDistribution = "ARCHIVE"
// Cluster shrink exception thrown if we try to set numberOfNodes to 1, so only apply if > 1
if (_numNodes > 1) numberOfNodes = _numNodes
// When running integration tests it doesn't forward the --debug-jvm to the cluster anymore
// i.e. we have to use a custom property to flag when we want to debug elasticsearch JVM
// since we also support multi node integration tests we increase debugPort per node
if (System.getProperty("opensearch.debug") != null) {
def debugPort = 5005
nodes.forEach { node ->
node.jvmArgs("-agentlib:jdwp=transport=dt_socket,server=n,suspend=y,address=*:${debugPort}")
debugPort += 1
}
}
}