-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathbuild.sbt
More file actions
262 lines (236 loc) · 9.26 KB
/
build.sbt
File metadata and controls
262 lines (236 loc) · 9.26 KB
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
import scala.sys.process.Process
import scala.io.Source
import xerial.sbt.Sonatype._
ThisBuild / sonatypeCredentialHost := sonatypeCentralHost
import Dependencies._
// Load Sonatype Central credentials
credentials += {
val credFile = Path.userHome / ".sbt" / "sonatype_central_credentials"
if (credFile.exists) {
val lines = Source.fromFile(credFile).getLines().toList
val props = lines.map { line =>
val parts = line.split("=", 2)
if (parts.length == 2) Some(parts(0).trim -> parts(1).trim) else None
}.flatten.toMap
Credentials(
"Sonatype Nexus Repository Manager",
props.getOrElse("host", "central.sonatype.com"),
props.getOrElse("user", ""),
props.getOrElse("password", "")
)
} else {
Credentials(Path.userHome / ".sbt" / "sonatype.credentials")
}
}
ThisBuild / organizationName := "zilliz"
ThisBuild / organizationHomepage := Some(url("https://zilliz.com/"))
// For cross-compiling (if applicable)
// crossScalaVersions := Seq("2.12.x", "2.13.x")
ThisBuild / scalaVersion := "2.13.16"
ThisBuild / description := "Milvus Spark Connector to use in Spark ETLs to populate a Milvus vector database."
ThisBuild / versionScheme := Some("early-semver")
// Remove all additional repository other than Maven Central from POM
ThisBuild / pomIncludeRepository := { _ => false }
ThisBuild / publishMavenStyle := true
ThisBuild / publishTo := {
val centralSnapshots =
"https://central.sonatype.com/repository/maven-snapshots/"
if (isSnapshot.value) Some("central-snapshots" at centralSnapshots)
else localStaging.value
}
ThisBuild / licenses := List(
"Server Side Public License v1" -> new URL(
"https://raw.githubusercontent.com/mongodb/mongo/refs/heads/master/LICENSE-Community.txt"
),
"GNU Affero General Public License v3 (AGPLv3)" -> new URL(
"https://www.gnu.org/licenses/agpl-3.0.txt"
)
)
ThisBuild / homepage := Some(
url("https://github.com/zilliztech/milvus-spark-connector")
)
ThisBuild / scmInfo := Some(
ScmInfo(
url("https://github.com/zilliztech/milvus-spark-connector"),
"scm:git@github.com:zilliztech/milvus-spark-connector.git"
)
)
ThisBuild / developers := List(
Developer(
id = "santiago-wjq",
name = "Santiago Wu",
email = "santiago.wu@zilliz.com",
url = url("https://github.com/santiago-wjq")
)
)
lazy val arch = System.getProperty("os.arch") match {
case "amd64" | "x86_64" => "amd64"
case "aarch64" | "arm64" => "arm64"
case other => other
}
// Get git branch name from env var (for Docker builds) or git command, sanitize for Maven version
lazy val gitBranch = {
val branch = sys.env.getOrElse("GIT_BRANCH",
scala.util.Try(Process("git rev-parse --abbrev-ref HEAD").!!.trim).getOrElse("unknown")
)
// Replace invalid characters for Maven version (only alphanumeric, dash, dot, underscore allowed)
branch.replaceAll("[^a-zA-Z0-9._-]", "-")
}
lazy val root = (project in file("."))
.settings(
name := "spark-connector",
assembly / parallelExecution := true,
assembly / assemblyPackageScala / assembleArtifact := false,
Test / parallelExecution := true,
Compile / compile / parallelExecution := true,
version := s"${gitBranch}-${arch}-SNAPSHOT",
organization := "com.zilliz",
// Disable Scaladoc and sources jar for publish (not needed, speeds up build)
Compile / packageDoc / publishArtifact := false,
Compile / packageSrc / publishArtifact := false,
// Fork JVM for run and tests to properly load native libraries
run / fork := true,
Test / fork := true,
// Show test logs immediately (don't buffer)
Test / logBuffered := false,
// Test timeout - 10 seconds per test to avoid hanging
Test / testOptions += Tests.Argument(TestFrameworks.ScalaTest, "-oDF", "-W", "10", "10"),
// JVM options for run
run / javaOptions ++= Seq(
"-Xss2m",
"-Djava.library.path=.",
"--add-opens=java.base/java.nio=ALL-UNNAMED"
),
run / envVars := Map(
"LD_PRELOAD" -> (baseDirectory.value / s"src/main/resources/native/libmilvus-storage.so").getAbsolutePath
),
// Include test dependencies in run classpath for example applications
Compile / run / fullClasspath := (Compile / run / fullClasspath).value ++ (Test / fullClasspath).value,
// JVM options for tests
Test / javaOptions ++= Seq(
"-Xss2m",
"-Xmx4g",
s"-Djava.library.path=${(baseDirectory.value / "src/main/resources/native").getAbsolutePath}",
"-Dlog4j2.configurationFile=log4j2.properties",
"-Dlog4j2.debug=false",
"--add-opens=java.base/java.nio=ALL-UNNAMED",
"--add-opens=java.base/java.lang=ALL-UNNAMED",
"--add-opens=java.base/java.lang.invoke=ALL-UNNAMED",
"--add-opens=java.base/java.util=ALL-UNNAMED",
"--add-opens=java.base/sun.security.action=ALL-UNNAMED"
),
Test / envVars := Map(
"LD_LIBRARY_PATH" -> (baseDirectory.value / "src/main/resources/native").getAbsolutePath
),
// Add milvus-storage JNI library as unmanaged dependency
Compile / unmanagedJars += baseDirectory.value / "milvus-storage" / "java" / "target" / "scala-2.13" / "milvus-storage-jni_2.13-0.1.0-SNAPSHOT.jar",
Test / unmanagedJars += baseDirectory.value / "milvus-storage" / "java" / "target" / "scala-2.13" / "milvus-storage-jni_2.13-0.1.0-SNAPSHOT.jar",
// 老 log binding (slf4j-log4j12 / reload4j / log4j 1.x) 与 spark 的 log4j2 冲突,
// 全局排除掉。
excludeDependencies ++= Seq(
ExclusionRule("org.slf4j", "slf4j-log4j12"),
ExclusionRule("org.slf4j", "slf4j-reload4j"),
ExclusionRule("log4j", "log4j"),
ExclusionRule("ch.qos.reload4j", "reload4j")
),
// 在 assembly 阶段过滤掉 slf4j-api jar:
// 编译时仍可用(来自传递依赖),但不进 fat jar,运行时由 spark 镜像
// /opt/spark/jars/slf4j-api-2.x.jar 提供,避免 userClassPathFirst=true 时
// Logger 被加载两份触发 LinkageError
assembly / assemblyExcludedJars := {
val cp = (assembly / fullClasspath).value
cp.filter { f =>
val n = f.data.getName
n.startsWith("slf4j-api-")
}
},
libraryDependencies ++= Seq(
munit % Test,
scalaTest % Test,
grpcNetty,
scalapbRuntime % "protobuf",
scalapbRuntimeGrpc,
scalapbCompilerPlugin,
sparkCore,
sparkSql,
sparkCatalyst,
sparkMLlib,
parquetHadoop,
parquetAvro,
avro,
hadoopCommon,
hadoopAws,
awsSdkS3,
awsSdkS3Transfer,
awsSdkCore,
jacksonScala,
jacksonDatabind,
arrowFormat,
arrowVector,
arrowMemoryCore,
arrowMemoryNetty,
arrowCData
),
Compile / PB.protoSources += baseDirectory.value / "milvus-proto/proto",
Compile / PB.targets := Seq(
scalapb.gen(grpc = true) -> (Compile / sourceManaged).value / "scalapb"
),
Compile / unmanagedSourceDirectories += (
Compile / PB.targets
).value.head.outputPath,
Compile / packageBin / mappings ++= {
val base = (Compile / PB.targets).value.head.outputPath
(base ** "*.scala").get.map { file =>
file -> s"generated_protobuf/${file.relativeTo(base).getOrElse(file)}"
}
},
Compile / resourceDirectories += baseDirectory.value / "src" / "main" / "resources",
// 发布 assembly JAR 作为单独的 artifact,带 classifier
assembly / artifact := {
val art = (assembly / artifact).value
art.withClassifier(Some("assembly"))
},
addArtifact(assembly / artifact, assembly)
)
assembly / assemblyShadeRules := Seq(
ShadeRule.rename("com.google.protobuf.**" -> "shade_proto.@1").inAll,
ShadeRule.rename("com.google.common.**" -> "shade_googlecommon.@1").inAll
// Note: Arrow cannot be shaded due to JNI bindings with hardcoded class names
// Use spark.driver.userClassPathFirst=true to prioritize our Arrow version
)
assembly / assemblyMergeStrategy := {
case PathList("native", xs @ _*) => MergeStrategy.first
// Handle all Netty native-image files
case PathList("META-INF", "native-image", "io.netty", _*) =>
MergeStrategy.discard
// Handle Netty version properties
case PathList("META-INF", "io.netty.versions.properties") =>
MergeStrategy.discard
// Handle mime.types
case PathList("mime.types") =>
MergeStrategy.filterDistinctLines
// Handle FastDoubleParser notice
case PathList("META-INF", "FastDoubleParser-NOTICE") =>
MergeStrategy.discard
// Handle Arrow git properties
case PathList("arrow-git.properties") =>
MergeStrategy.first
// Handle module-info.class files
case x if x.endsWith("module-info.class") =>
MergeStrategy.discard
// Handle hadoop package-info conflicts
case PathList("org", "apache", "hadoop", xs @ _*) if xs.last == "package-info.class" =>
MergeStrategy.first
// Handle AWS SDK VersionInfo conflicts
case PathList("software", "amazon", "awssdk", xs @ _*) if xs.last == "VersionInfo.class" =>
MergeStrategy.first
// Default case
case x =>
val oldStrategy = (ThisBuild / assemblyMergeStrategy).value
oldStrategy(x)
}
// import scalapb.compiler.Version
// val grpcJavaVersion =
// SettingKey[String]("grpcJavaVersion", "ScalaPB gRPC Java version")
// grpcJavaVersion := Version.grpcJavaVersion
// See https://www.scala-sbt.org/1.x/docs/Using-Sonatype.html for instructions on how to publish to Sonatype.