forked from apache/gravitino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
511 lines (454 loc) · 15.7 KB
/
build.gradle.kts
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
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
/*
* Copyright 2023 Datastrato Pvt Ltd.
* This software is licensed under the Apache License version 2.
*/
import com.github.gradle.node.NodeExtension
import com.github.gradle.node.NodePlugin
import com.github.jk1.license.filter.DependencyFilter
import com.github.jk1.license.filter.LicenseBundleNormalizer
import com.github.jk1.license.render.InventoryHtmlReportRenderer
import com.github.jk1.license.render.ReportRenderer
import com.github.vlsi.gradle.dsl.configureEach
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.internal.hash.ChecksumService
import org.gradle.internal.os.OperatingSystem
import org.gradle.kotlin.dsl.support.serviceOf
import java.io.File
import java.util.Locale
plugins {
`maven-publish`
id("java")
id("idea")
id("jacoco")
alias(libs.plugins.gradle.extensions)
alias(libs.plugins.node) apply false
// Spotless version < 6.19.0 (https://github.com/diffplug/spotless/issues/1819) has an issue
// running against JDK21, but we cannot upgrade the spotless to 6.19.0 or later since it only
// support JDK11+. So we don't support JDK21 and thrown an exception for now.
if (JavaVersion.current() >= JavaVersion.VERSION_1_8 &&
JavaVersion.current() <= JavaVersion.VERSION_17
) {
alias(libs.plugins.spotless)
} else {
throw GradleException(
"Gravitino Gradle toolchain current doesn't support " +
"Java version: ${JavaVersion.current()}. Please use JDK8 to 17."
)
}
alias(libs.plugins.publish)
// Apply one top level rat plugin to perform any required license enforcement analysis
alias(libs.plugins.rat)
alias(libs.plugins.bom)
alias(libs.plugins.dependencyLicenseReport)
alias(libs.plugins.tasktree)
}
if (extra["jdkVersion"] !in listOf("8", "11", "17")) {
throw GradleException(
"Gravitino current doesn't support building with " +
"Java version: ${extra["jdkVersion"]}. Please use JDK8, 11 or 17."
)
}
project.extra["extraJvmArgs"] = if (extra["jdkVersion"] in listOf("8", "11")) {
listOf()
} else {
listOf(
"-XX:+IgnoreUnrecognizedVMOptions",
"--add-opens", "java.base/java.io=ALL-UNNAMED",
"--add-opens", "java.base/java.lang.invoke=ALL-UNNAMED",
"--add-opens", "java.base/java.lang.reflect=ALL-UNNAMED",
"--add-opens", "java.base/java.lang=ALL-UNNAMED",
"--add-opens", "java.base/java.math=ALL-UNNAMED",
"--add-opens", "java.base/java.net=ALL-UNNAMED",
"--add-opens", "java.base/java.nio=ALL-UNNAMED",
"--add-opens", "java.base/java.text=ALL-UNNAMED",
"--add-opens", "java.base/java.time=ALL-UNNAMED",
"--add-opens", "java.base/java.util.concurrent.atomic=ALL-UNNAMED",
"--add-opens", "java.base/java.util.concurrent=ALL-UNNAMED",
"--add-opens", "java.base/java.util.regex=ALL-UNNAMED",
"--add-opens", "java.base/java.util=ALL-UNNAMED",
"--add-opens", "java.base/jdk.internal.ref=ALL-UNNAMED",
"--add-opens", "java.base/jdk.internal.reflect=ALL-UNNAMED",
"--add-opens", "java.sql/java.sql=ALL-UNNAMED",
"--add-opens", "java.base/sun.util.calendar=ALL-UNNAMED",
"--add-opens", "java.base/sun.nio.ch=ALL-UNNAMED",
"--add-opens", "java.base/sun.nio.cs=ALL-UNNAMED",
"--add-opens", "java.base/sun.security.action=ALL-UNNAMED",
"--add-opens", "java.base/sun.util.calendar=ALL-UNNAMED"
)
}
licenseReport {
renderers = arrayOf<ReportRenderer>(InventoryHtmlReportRenderer("report.html", "Backend"))
filters = arrayOf<DependencyFilter>(LicenseBundleNormalizer())
}
repositories { mavenCentral() }
allprojects {
if ((project.name != "catalogs") && project.name != "clients") {
apply(plugin = "com.diffplug.spotless")
repositories {
mavenCentral()
mavenLocal()
}
plugins.withType<com.diffplug.gradle.spotless.SpotlessPlugin>().configureEach {
configure<com.diffplug.gradle.spotless.SpotlessExtension> {
java {
// Fix the Google Java Format version to 1.7. Since JDK8 only support Google Java Format
// 1.7, which is not compatible with JDK17. We will use a newer version when we upgrade to
// JDK17.
googleJavaFormat("1.7")
removeUnusedImports()
trimTrailingWhitespace()
replaceRegex(
"Remove wildcard imports",
"import\\s+[^\\*\\s]+\\*;(\\r\\n|\\r|\\n)",
"$1"
)
replaceRegex(
"Remove static wildcard imports",
"import\\s+(?:static\\s+)?[^*\\s]+\\*;(\\r\\n|\\r|\\n)",
"$1"
)
targetExclude("**/build/**")
}
kotlinGradle {
target("*.gradle.kts")
ktlint().editorConfigOverride(mapOf("indent_size" to 2))
}
}
}
}
}
nexusPublishing {
repositories {
sonatype {
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
val sonatypeUser =
System.getenv("SONATYPE_USER").takeUnless { it.isNullOrEmpty() }
?: extra["SONATYPE_USER"].toString()
val sonatypePassword =
System.getenv("SONATYPE_PASSWORD").takeUnless { it.isNullOrEmpty() }
?: extra["SONATYPE_PASSWORD"].toString()
username.set(sonatypeUser)
password.set(sonatypePassword)
}
}
packageGroup.set("com.datastrato.gravitino")
}
dependencies {
testImplementation(libs.testng)
}
subprojects {
apply(plugin = "jacoco")
apply(plugin = "maven-publish")
apply(plugin = "java")
repositories {
mavenCentral()
mavenLocal()
}
java {
toolchain {
// Some JDK vendors like Homebrew installed OpenJDK 17 have problems in building trino-connector:
// It will cause tests of Trino-connector hanging forever on macOS, to avoid this issue and
// other vendor-related problems, Gravitino will use the specified AMAZON OpenJDK 17 to build
// Trino-connector on macOS.
if (project.name == "trino-connector") {
if (OperatingSystem.current().isMacOsX) {
vendor.set(JvmVendorSpec.AMAZON)
}
languageVersion.set(JavaLanguageVersion.of(17))
} else {
languageVersion.set(JavaLanguageVersion.of(extra["jdkVersion"].toString().toInt()))
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
}
}
if ((project.name == "catalogs") || project.name == "clients") {
tasks.withType<Jar> {
enabled = false
}
}
gradle.projectsEvaluated {
tasks.withType<JavaCompile> {
options.compilerArgs.addAll(arrayOf("-Xlint:deprecation", "-Werror"))
}
}
tasks.withType<Javadoc> {
options.encoding = "UTF-8"
options.locale = "en_US"
}
val sourcesJar by tasks.registering(Jar::class) {
from(sourceSets.named("main").get().allSource)
archiveClassifier.set("sources")
}
val javadocJar by tasks.registering(Jar::class) {
archiveClassifier.set("javadoc")
from(tasks["javadoc"])
}
if (project.name in listOf("web", "docs")) {
plugins.apply(NodePlugin::class)
configure<NodeExtension> {
version.set("20.9.0")
nodeProjectDir.set(file("$rootDir/.node"))
download.set(true)
}
}
apply(plugin = "signing")
publishing {
publications {
create<MavenPublication>("MavenJava") {
from(components["java"])
artifact(sourcesJar)
artifact(javadocJar)
pom {
name.set("Gravitino")
description.set("Gravitino is a high-performance, geo-distributed and federated metadata lake.")
url.set("https://datastrato.ai")
licenses {
license {
name.set("The Apache Software License, Version 2.0")
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
}
}
developers {
developer {
id.set("The maintainers of Gravitino")
name.set("support")
email.set("[email protected]")
}
}
scm {
url.set("https://github.com/datastrato/gravitino")
connection.set("scm:git:git://github.com/datastrato/gravitino.git")
}
}
}
}
}
configure<SigningExtension> {
val gpgId = System.getenv("GPG_ID")
val gpgSecretKey = System.getenv("GPG_PRIVATE_KEY")
val gpgKeyPassword = System.getenv("GPG_PASSPHRASE")
useInMemoryPgpKeys(gpgId, gpgSecretKey, gpgKeyPassword)
sign(publishing.publications)
}
tasks.configureEach<Test> {
testLogging {
exceptionFormat = TestExceptionFormat.FULL
showExceptions = true
showCauses = true
showStackTraces = true
}
reports.html.outputLocation.set(file("${rootProject.projectDir}/build/reports/"))
val skipTests = project.hasProperty("skipTests")
if (!skipTests) {
if (project.name == "trino-connector") {
useTestNG()
maxHeapSize = "2G"
} else {
useJUnitPlatform()
}
jvmArgs(project.property("extraJvmArgs") as List<*>)
finalizedBy(tasks.getByName("jacocoTestReport"))
}
}
tasks.withType<JacocoReport> {
reports {
csv.required.set(true)
xml.required.set(true)
html.required.set(true)
}
}
tasks.register("allDeps", DependencyReportTask::class)
group = "com.datastrato.gravitino"
version = "$version"
tasks.withType<Jar> {
archiveBaseName.set("${rootProject.name.lowercase(Locale.getDefault())}-${project.name}")
if (project.name == "server") {
from(sourceSets.main.get().resources)
setDuplicatesStrategy(DuplicatesStrategy.INCLUDE)
}
if (project.name != "integration-test") {
exclude("log4j2.properties")
exclude("test/**")
}
}
}
tasks.rat {
substringMatcher("DS", "Datastrato", "Copyright 2023 Datastrato Pvt Ltd.")
substringMatcher("DS", "Datastrato", "Copyright 2024 Datastrato Pvt Ltd.")
approvedLicense("Datastrato")
approvedLicense("Apache License Version 2.0")
// Set input directory to that of the root project instead of the CWD. This
// makes .gitignore rules (added below) work properly.
inputDir.set(project.rootDir)
val exclusions = mutableListOf(
// Ignore files we track but do not need headers
"**/.github/**/*",
"dev/docker/**/*.xml",
"**/*.log",
"**/licenses/*.txt",
"**/licenses/*.md",
"integration-test/**",
"web/.**",
"web/next-env.d.ts",
"web/dist/**/*",
"web/node_modules/**/*",
"web/lib/utils/axios/**/*",
"web/lib/enums/httpEnum.ts",
"web/types/axios.d.ts",
"web/yarn.lock",
"web/package-lock.json",
"web/pnpm-lock.yaml",
"**/LICENSE.*",
"**/NOTICE.*"
)
// Add .gitignore excludes to the Apache Rat exclusion list.
val gitIgnore = project(":").file(".gitignore")
if (gitIgnore.exists()) {
val gitIgnoreExcludes = gitIgnore.readLines().filter {
it.isNotEmpty() && !it.startsWith("#")
}
exclusions.addAll(gitIgnoreExcludes)
}
dependsOn(":web:nodeSetup")
verbose.set(true)
failOnError.set(true)
setExcludes(exclusions)
}
tasks.check.get().dependsOn(tasks.rat)
tasks.cyclonedxBom {
setIncludeConfigs(listOf("runtimeClasspath"))
}
jacoco {
toolVersion = "0.8.10"
reportsDirectory.set(layout.buildDirectory.dir("JacocoReport"))
}
tasks {
val projectDir = layout.projectDirectory
val outputDir = projectDir.dir("distribution")
val compileDistribution by registering {
dependsOn("copySubprojectDependencies", "copyCatalogLibAndConfigs", "copySubprojectLib")
group = "gravitino distribution"
outputs.dir(projectDir.dir("distribution/package"))
doLast {
copy {
from(projectDir.dir("conf")) { into("package/conf") }
from(projectDir.dir("bin")) { into("package/bin") }
from(projectDir.dir("web/build/libs/${rootProject.name}-web-$version.war")) { into("package/web") }
into(outputDir)
rename { fileName ->
fileName.replace(".template", "")
}
fileMode = 0b111101101
}
copy {
from(projectDir.dir("licenses")) { into("package/licenses") }
from(projectDir.file("LICENSE.bin")) { into("package") }
from(projectDir.file("NOTICE.bin")) { into("package") }
from(projectDir.file("README.md")) { into("package") }
into(outputDir)
rename { fileName ->
fileName.replace(".bin", "")
}
}
// Create the directory 'data' for storage.
val directory = File("distribution/package/data")
directory.mkdirs()
}
}
val assembleDistribution by registering(Tar::class) {
dependsOn("assembleTrinoConnector")
group = "gravitino distribution"
finalizedBy("checksumDistribution")
into("${rootProject.name}-$version-bin")
from(compileDistribution.map { it.outputs.files.single() })
compression = Compression.GZIP
archiveFileName.set("${rootProject.name}-$version-bin.tar.gz")
destinationDirectory.set(projectDir.dir("distribution"))
}
val assembleTrinoConnector by registering(Tar::class) {
dependsOn("trino-connector:copyLibs")
group = "gravitino distribution"
finalizedBy("checksumTrinoConnector")
into("${rootProject.name}-trino-connector-$version")
from("trino-connector/build/libs")
compression = Compression.GZIP
archiveFileName.set("${rootProject.name}-trino-connector-$version.tar.gz")
destinationDirectory.set(projectDir.dir("distribution"))
}
register("checksumDistribution") {
group = "gravitino distribution"
dependsOn(assembleDistribution, "checksumTrinoConnector")
val archiveFile = assembleDistribution.flatMap { it.archiveFile }
val checksumFile = archiveFile.map { archive ->
archive.asFile.let { it.resolveSibling("${it.name}.sha256") }
}
inputs.file(archiveFile)
outputs.file(checksumFile)
doLast {
checksumFile.get().writeText(
serviceOf<ChecksumService>().sha256(archiveFile.get().asFile).toString()
)
}
}
register("checksumTrinoConnector") {
group = "gravitino distribution"
dependsOn(assembleTrinoConnector)
val archiveFile = assembleTrinoConnector.flatMap { it.archiveFile }
val checksumFile = archiveFile.map { archive ->
archive.asFile.let { it.resolveSibling("${it.name}.sha256") }
}
inputs.file(archiveFile)
outputs.file(checksumFile)
doLast {
checksumFile.get().writeText(
serviceOf<ChecksumService>().sha256(archiveFile.get().asFile).toString()
)
}
}
val cleanDistribution by registering(Delete::class) {
group = "gravitino distribution"
delete(outputDir)
}
register("copySubprojectDependencies", Copy::class) {
subprojects.forEach() {
if (!it.name.startsWith("catalog") &&
!it.name.startsWith("client") && it.name != "trino-connector" &&
it.name != "integration-test" && it.name != "bundled-catalog"
) {
from(it.configurations.runtimeClasspath)
into("distribution/package/libs")
}
}
}
register("copySubprojectLib", Copy::class) {
subprojects.forEach() {
if (!it.name.startsWith("catalog") &&
!it.name.startsWith("client") &&
it.name != "trino-connector" &&
it.name != "integration-test" &&
it.name != "bundled-catalog"
) {
dependsOn("${it.name}:build")
from("${it.name}/build/libs")
into("distribution/package/libs")
include("*.jar")
setDuplicatesStrategy(DuplicatesStrategy.INCLUDE)
}
}
}
register("copyCatalogLibAndConfigs", Copy::class) {
dependsOn(
":catalogs:catalog-hive:copyLibAndConfig",
":catalogs:catalog-lakehouse-iceberg:copyLibAndConfig",
":catalogs:catalog-jdbc-mysql:copyLibAndConfig",
":catalogs:catalog-jdbc-postgresql:copyLibAndConfig"
// TODO. add fileset catalog to the distribution when ready.
)
}
clean {
dependsOn(cleanDistribution)
}
}
apply(plugin = "com.dorongold.task-tree")