forked from unitycatalog/unitycatalog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sbt
442 lines (403 loc) · 18.4 KB
/
build.sbt
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
import java.nio.file.Files
import java.io.File
import Tarball.createTarballSettings
import sbt.util
import sbtlicensereport.license.{DepModuleInfo, LicenseCategory, LicenseInfo}
import ReleaseSettings.{javaOnlyReleaseSettings, rootReleaseSettings, skipReleaseSettings}
import scala.jdk.CollectionConverters.asJavaIterableConverter
import scala.language.implicitConversions
val orgName = "io.unitycatalog"
val artifactNamePrefix = "unitycatalog"
lazy val commonSettings = Seq(
organization := orgName,
// Compilation configs
initialize := {
// Assert that the JVM is at least Java 17
val _ = initialize.value // ensure previous initializations are run
assert(
sys.props("java.specification.version").toDouble >= 17,
"Java 17 or above is required to run this project.")
},
Compile / compile / javacOptions ++= Seq(
"-Xlint:deprecation",
"-Xlint:unchecked",
"-source", "17",
"-target", "17",
"-g:source,lines,vars",
),
libraryDependencies ++= Seq(
"org.slf4j" % "slf4j-api" % "2.0.13",
"org.slf4j" % "slf4j-log4j12" % "2.0.13" % Test,
"org.apache.logging.log4j" % "log4j-slf4j2-impl" % "2.23.1",
"org.apache.logging.log4j" % "log4j-api" % "2.23.1"
),
resolvers += Resolver.mavenLocal,
autoScalaLibrary := false,
crossPaths := false, // No scala cross building
assembly / assemblyMergeStrategy := {
case PathList("META-INF", xs @ _*) => MergeStrategy.discard
case x => MergeStrategy.first
},
// Test configs
Test / testOptions := Seq(Tests.Argument(TestFrameworks.JUnit, "-a", "-v", "-q"), Tests.Filter(name => !(name startsWith s"$orgName.server.base"))),
Test / logLevel := util.Level.Info,
Test / publishArtifact := false,
fork := true,
outputStrategy := Some(StdoutOutput),
Compile / packageBin := {
val packageFile = (Compile / packageBin).value
generateClasspathFile(
targetDir = packageFile.getParentFile,
classpath = (Runtime / dependencyClasspath).value)
packageFile
},
licenseConfigurations := Set("compile"),
licenseOverrides := {
case DepModuleInfo("io.unitycatalog", _, _) =>
LicenseInfo(LicenseCategory.Apache, "Apache 2.0", "http://www.apache.org/licenses")
case DepModuleInfo("org.hibernate.common", "hibernate-commons-annotations", _) =>
// Apache 2.0: https://mvnrepository.com/artifact/org.hibernate.common/hibernate-commons-annotations
LicenseInfo(LicenseCategory.Apache, "Apache 2.0", "http://www.apache.org/licenses")
},
licenseDepExclusions := {
// LGPL 2.1: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
// https://en.wikipedia.org/wiki/GNU_Lesser_General_Public_License
// We can use and distribute the, but not modify the source code
case DepModuleInfo("org.hibernate.orm", _, _) => true
// Duo license:
// - Eclipse Public License 2.0
// - GNU General Public License, version 2 with the GNU Classpath Exception
// I think we're good with the classpath exception in there.
case DepModuleInfo("jakarta.transaction", "jakarta.transaction-api", _) => true
},
assembly / test := {}
)
enablePlugins(CoursierPlugin)
useCoursier := true
// Configure resolvers
resolvers ++= Seq(
"Sonatype OSS Releases" at "https://oss.sonatype.org/content/repositories/releases/",
"Maven Central" at "https://repo1.maven.org/maven2/",
)
def javaCheckstyleSettings(configLocation: File) = Seq(
checkstyleConfigLocation := CheckstyleConfigLocation.File(configLocation.toString),
checkstyleSeverityLevel := Some(CheckstyleSeverityLevel.Error),
// (Compile / compile) := ((Compile / compile) dependsOn (Compile / checkstyle)).value,
// (Test / test) := ((Test / test) dependsOn (Test / checkstyle)).value,
)
// enforce java code style
def javafmtCheckSettings() = Seq(
(Compile / compile) := ((Compile / compile) dependsOn (Compile / javafmtCheckAll)).value
)
lazy val client = (project in file("target/clients/java"))
.enablePlugins(OpenApiGeneratorPlugin)
.disablePlugins(JavaFormatterPlugin)
.settings(
name := s"$artifactNamePrefix-client",
commonSettings,
javaOnlyReleaseSettings,
libraryDependencies ++= Seq(
"com.fasterxml.jackson.core" % "jackson-annotations" % jacksonVersion,
"com.fasterxml.jackson.core" % "jackson-core" % jacksonVersion,
"com.fasterxml.jackson.core" % "jackson-databind" % jacksonVersion,
"com.fasterxml.jackson.datatype" % "jackson-datatype-jsr310" % jacksonVersion,
"org.openapitools" % "jackson-databind-nullable" % openApiToolsJacksonBindNullableVersion,
"com.google.code.findbugs" % "jsr305" % "3.0.2",
"jakarta.annotation" % "jakarta.annotation-api" % "3.0.0" % Provided,
// Test dependencies
"org.junit.jupiter" % "junit-jupiter" % "5.10.3" % Test,
"net.aichler" % "jupiter-interface" % JupiterKeys.jupiterVersion.value % Test,
"org.assertj" % "assertj-core" % "3.26.3" % Test,
),
(Compile / compile) := ((Compile / compile) dependsOn generate).value,
// OpenAPI generation specs
openApiInputSpec := (file(".") / "api" / "all.yaml").toString,
openApiGeneratorName := "java",
openApiOutputDir := (file("target") / "clients" / "java").toString,
openApiApiPackage := s"$orgName.client.api",
openApiModelPackage := s"$orgName.client.model",
openApiAdditionalProperties := Map(
"library" -> "native",
"useJakartaEe" -> "true",
"hideGenerationTimestamp" -> "true"),
openApiGenerateApiTests := SettingDisabled,
openApiGenerateModelTests := SettingDisabled,
openApiGenerateApiDocumentation := SettingDisabled,
openApiGenerateModelDocumentation := SettingDisabled,
// Define the simple generate command to generate full client codes
generate := {
val _ = openApiGenerate.value
// Delete the generated build.sbt file so that it is not used for our sbt config
val buildSbtFile = file(openApiOutputDir.value) / "build.sbt"
if (buildSbtFile.exists()) {
buildSbtFile.delete()
}
}
)
lazy val apiDocs = (project in file("api"))
.enablePlugins(OpenApiGeneratorPlugin)
.settings(
name := s"$artifactNamePrefix-docs",
// OpenAPI generation specs
openApiInputSpec := (file("api") / "all.yaml").toString,
openApiGeneratorName := "markdown",
openApiOutputDir := (file("api")).toString,
// Define the simple generate command to generate markdown docs
generate := {
val _ = openApiGenerate.value
}
)
// Define the custom task key
lazy val populateTestDB = taskKey[Unit]("Run PopulateTestDatabase main class from the test folder")
lazy val server = (project in file("server"))
.dependsOn(client % "test->test")
.dependsOn(serverModels)
.settings (
name := s"$artifactNamePrefix-server",
commonSettings,
javaOnlyReleaseSettings,
javafmtCheckSettings,
javaCheckstyleSettings(file("dev") / "checkstyle-config.xml"),
libraryDependencies ++= Seq(
"com.linecorp.armeria" % "armeria" % "1.28.4",
// Netty dependencies
"io.netty" % "netty-all" % "4.1.111.Final",
"jakarta.annotation" % "jakarta.annotation-api" % "3.0.0" % Provided,
// Jackson dependencies
"com.fasterxml.jackson.core" % "jackson-annotations" % jacksonVersion,
"com.fasterxml.jackson.core" % "jackson-core" % jacksonVersion,
"com.fasterxml.jackson.core" % "jackson-databind" % jacksonVersion,
"com.fasterxml.jackson.datatype" % "jackson-datatype-jsr310" % jacksonVersion,
"com.google.code.findbugs" % "jsr305" % "3.0.2",
"com.h2database" % "h2" % "2.2.224",
"org.hibernate.orm" % "hibernate-core" % "6.5.0.Final",
"org.openapitools" % "jackson-databind-nullable" % openApiToolsJacksonBindNullableVersion,
"jakarta.activation" % "jakarta.activation-api" % "2.1.3",
"net.bytebuddy" % "byte-buddy" % "1.14.15",
"org.projectlombok" % "lombok" % "1.18.32" % Provided,
//For s3 access
"com.amazonaws" % "aws-java-sdk-s3" % "1.12.728",
"org.apache.httpcomponents" % "httpcore" % "4.4.16",
"org.apache.httpcomponents" % "httpclient" % "4.5.14",
// Iceberg REST Catalog dependencies
"org.apache.iceberg" % "iceberg-core" % "1.5.2",
"org.apache.iceberg" % "iceberg-aws" % "1.5.2",
"software.amazon.awssdk" % "s3" % "2.24.0",
"io.vertx" % "vertx-core" % "4.3.5",
"io.vertx" % "vertx-web" % "4.3.5",
"io.vertx" % "vertx-web-client" % "4.3.5",
// Test dependencies
"org.junit.jupiter" % "junit-jupiter" % "5.10.3" % Test,
"org.mockito" % "mockito-core" % "5.11.0" % Test,
"org.mockito" % "mockito-inline" % "5.2.0" % Test,
"org.mockito" % "mockito-junit-jupiter" % "5.12.0" % Test,
"net.aichler" % "jupiter-interface" % JupiterKeys.jupiterVersion.value % Test,
"com.adobe.testing" % "s3mock-junit5" % "3.9.1" % Test
exclude("ch.qos.logback", "logback-classic")
exclude("org.apache.logging.log4j", "log4j-to-slf4j"),
"javax.xml.bind" % "jaxb-api" % "2.3.1" % Test,
// CLI dependencies
"commons-cli" % "commons-cli" % "1.7.0"
),
Compile / compile / javacOptions ++= Seq(
"-processor",
"lombok.launch.AnnotationProcessorHider$AnnotationProcessor"
),
Compile / sourceGenerators += Def.task {
val file = (Compile / sourceManaged).value / "io" / "unitycatalog" / "server" / "utils" / "VersionUtils.java"
IO.write(file,
s"""package io.unitycatalog.server.utils;
|
|public class VersionUtils {
| public static String VERSION = "${version.value}";
|}
|""".stripMargin)
Seq(file)
},
populateTestDB := {
val log = streams.value.log
(Test / runMain).toTask(s" io.unitycatalog.server.utils.PopulateTestDatabase").value
},
Test / javaOptions += s"-Duser.dir=${(ThisBuild / baseDirectory).value.getAbsolutePath}"
)
lazy val serverModels = (project in file("server") / "target" / "models")
.enablePlugins(OpenApiGeneratorPlugin)
.disablePlugins(JavaFormatterPlugin)
.settings(
name := s"$artifactNamePrefix-servermodels",
commonSettings,
(Compile / compile) := ((Compile / compile) dependsOn generate).value,
libraryDependencies ++= Seq(
"jakarta.annotation" % "jakarta.annotation-api" % "3.0.0" % Provided,
"com.fasterxml.jackson.core" % "jackson-annotations" % jacksonVersion,
),
// OpenAPI generation configs for generating model codes from the spec
openApiInputSpec := (file(".") / "api" / "all.yaml").toString,
openApiGeneratorName := "java",
openApiOutputDir := (file("server") / "target" / "models").toString,
openApiValidateSpec := SettingEnabled,
openApiGenerateMetadata := SettingDisabled,
openApiModelPackage := s"$orgName.server.model",
openApiAdditionalProperties := Map(
"library" -> "resteasy", // resteasy generates the most minimal models
"useJakartaEe" -> "true",
"hideGenerationTimestamp" -> "true"
),
openApiGlobalProperties := Map("models" -> ""),
openApiGenerateApiTests := SettingDisabled,
openApiGenerateModelTests := SettingDisabled,
openApiGenerateApiDocumentation := SettingDisabled,
openApiGenerateModelDocumentation := SettingDisabled,
// Define the simple generate command to generate model codes
generate := {
val _ = openApiGenerate.value
}
)
lazy val cli = (project in file("examples") / "cli")
.dependsOn(server % "test->test")
.dependsOn(client % "compile->compile;test->test")
.settings(
name := s"$artifactNamePrefix-cli",
mainClass := Some(orgName + ".cli.UnityCatalogCli"),
commonSettings,
skipReleaseSettings,
javafmtCheckSettings,
javaCheckstyleSettings(file("dev") / "checkstyle-config.xml"),
libraryDependencies ++= Seq(
"commons-cli" % "commons-cli" % "1.7.0",
"org.json" % "json" % "20240303",
"com.fasterxml.jackson.core" % "jackson-databind" % jacksonVersion,
"com.fasterxml.jackson.datatype" % "jackson-datatype-jsr310" % jacksonVersion,
"org.openapitools" % "jackson-databind-nullable" % openApiToolsJacksonBindNullableVersion,
"org.yaml" % "snakeyaml" % "2.2",
"io.delta" % "delta-kernel-api" % "3.2.0",
"io.delta" % "delta-kernel-defaults" % "3.2.0",
"io.delta" % "delta-storage" % "3.2.0",
"org.apache.hadoop" % "hadoop-client-api" % "3.4.0",
"org.apache.hadoop" % "hadoop-client-runtime" % "3.4.0",
"de.vandermeer" % "asciitable" % "0.3.2",
// for s3 access
"org.fusesource.jansi" % "jansi" % "2.4.1",
"com.amazonaws" % "aws-java-sdk-core" % "1.12.728",
"org.apache.hadoop" % "hadoop-aws" % "3.4.0",
"com.google.guava" % "guava" % "31.0.1-jre",
// Test dependencies
"org.junit.jupiter" % "junit-jupiter" % "5.10.3" % Test,
"net.aichler" % "jupiter-interface" % JupiterKeys.jupiterVersion.value % Test,
),
Test / javaOptions += s"-Duser.dir=${(ThisBuild / baseDirectory).value.getAbsolutePath}",
)
/*
* This project is a combination of the server and client projects, shaded into a single JAR.
* It also includes the test classes from the server project.
* It is used for the Spark connector project(the client is required as a compile dependency,
* and the server(with tests) is required as a test dependency)
* This was necessary because Spark 3.5 has a dependency on Jackson 2.15, which conflicts with the Jackson 2.17
*/
lazy val serverAndClientShaded = (project in file("server-and-client-shaded"))
.dependsOn(server % "compile->compile, test->compile")
.dependsOn(client % "compile->compile")
.settings(
name := s"${artifactNamePrefix}-server-shaded",
commonSettings,
skipReleaseSettings,
Compile / packageBin := assembly.value,
assembly / logLevel := Level.Warn,
assembly / test := {},
assembly / assemblyShadeRules := Seq(
ShadeRule.rename("com.fasterxml.**" -> "shaded.@0").inAll,
ShadeRule.rename("org.antlr.**" -> "shaded.@0").inAll,
),
assemblyPackageScala / assembleArtifact := false,
assembly / assemblyMergeStrategy := {
case PathList("META-INF", xs@_*) => MergeStrategy.discard
case _ => MergeStrategy.first
},
assembly / fullClasspath := {
val compileClasspath = (server / Compile / fullClasspath).value ++ (client / Compile / fullClasspath).value
val testClasses = (server / Test / products).value
compileClasspath ++ testClasses.map(Attributed.blank)
}
)
val sparkVersion = "3.5.1"
lazy val spark = (project in file("connectors/spark"))
.settings(
name := s"$artifactNamePrefix-spark",
scalaVersion := "2.12.15",
commonSettings,
javaOptions ++= Seq(
"--add-opens=java.base/sun.nio.ch=ALL-UNNAMED",
),
javaCheckstyleSettings(file("dev/checkstyle-config.xml")),
libraryDependencies ++= Seq(
"org.apache.spark" %% "spark-sql" % sparkVersion,
"com.fasterxml.jackson.core" % "jackson-databind" % "2.15.0",
"com.fasterxml.jackson.module" %% "jackson-module-scala" % "2.15.0",
"com.fasterxml.jackson.core" % "jackson-annotations" % "2.15.0",
"com.fasterxml.jackson.core" % "jackson-core" % "2.15.0",
"org.antlr" % "antlr4-runtime" % "4.9.3",
"org.antlr" % "antlr4" % "4.9.3",
),
libraryDependencies ++= Seq(
// Test dependencies
"org.junit.jupiter" % "junit-jupiter" % "5.10.3" % Test,
"org.assertj" % "assertj-core" % "3.26.3" % Test,
"org.mockito" % "mockito-core" % "5.11.0" % Test,
"org.mockito" % "mockito-inline" % "5.2.0" % Test,
"org.mockito" % "mockito-junit-jupiter" % "5.12.0" % Test,
"net.aichler" % "jupiter-interface" % JupiterKeys.jupiterVersion.value % Test,
"org.apache.hadoop" % "hadoop-client-runtime" % "3.4.0",
"io.delta" %% "delta-spark" % "3.2.0" % Test,
),
dependencyOverrides ++= Seq(
"com.fasterxml.jackson.core" % "jackson-databind" % "2.15.0",
"com.fasterxml.jackson.module" %% "jackson-module-scala" % "2.15.0",
"com.fasterxml.jackson.core" % "jackson-annotations" % "2.15.0",
"com.fasterxml.jackson.core" % "jackson-core" % "2.15.0",
"org.antlr" % "antlr4-runtime" % "4.9.3",
"org.antlr" % "antlr4" % "4.9.3",
),
Compile / unmanagedJars += (serverAndClientShaded / assembly).value,
Test / unmanagedJars += (serverAndClientShaded / assembly).value,
licenseDepExclusions := {
case DepModuleInfo("org.hibernate.orm", _, _) => true
case DepModuleInfo("jakarta.annotation", "jakarta.annotation-api", _) => true
case DepModuleInfo("jakarta.servlet", "jakarta.servlet-api", _) => true
case DepModuleInfo("jakarta.transaction", "jakarta.transaction-api", _) => true
case DepModuleInfo("jakarta.ws.rs", "jakarta.ws.rs-api", _) => true
case DepModuleInfo("javax.activation", "activation", _) => true
case DepModuleInfo("javax.servlet", "javax.servlet-api", _) => true
case DepModuleInfo("org.glassfish.hk2", "hk2-api", _) => true
case DepModuleInfo("org.glassfish.hk2", "hk2-locator", _) => true
case DepModuleInfo("org.glassfish.hk2", "hk2-utils", _) => true
case DepModuleInfo("org.glassfish.hk2", "osgi-resource-locator", _) => true
case DepModuleInfo("org.glassfish.hk2.external", "aopalliance-repackaged", _) => true
case DepModuleInfo("ch.qos.logback", "logback-classic", _) => true
case DepModuleInfo("ch.qos.logback", "logback-core", _) => true
case DepModuleInfo("org.apache.xbean", "xbean-asm9-shaded", _) => true
case DepModuleInfo("oro", "oro", _) => true
case DepModuleInfo("org.glassfish", "javax.json", _) => true
case DepModuleInfo("org.glassfish.hk2.external", "jakarta.inject", _) => true
case DepModuleInfo("org.antlr", "ST4", _) => true,
}
)
lazy val root = (project in file("."))
.aggregate(serverModels, client, server, cli, spark)
.settings(
name := s"$artifactNamePrefix",
createTarballSettings(),
commonSettings,
rootReleaseSettings
)
def generateClasspathFile(targetDir: File, classpath: Classpath): Unit = {
// Generate a classpath file with the entire runtime class path.
// This is used by the launcher scripts for launching CLI directly with JAR instead of SBT.
val classpathFile = targetDir / "classpath"
Files.write(classpathFile.toPath, classpath.files.mkString(File.pathSeparator).getBytes)
println(s"Generated classpath file '$classpathFile'")
}
val generate = taskKey[Unit]("generate code from APIs")
// Library versions
val jacksonVersion = "2.17.0"
val openApiToolsJacksonBindNullableVersion = "0.2.6"
val log4jVersion = "2.23.1"