forked from datastax/spark-cassandra-connector
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathSparkCassandraConnectorBuild.scala
347 lines (301 loc) · 15.8 KB
/
SparkCassandraConnectorBuild.scala
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
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.io.File
import sbtsparkpackage.SparkPackagePlugin.autoImport._
import sbt.Keys._
import sbt._
object CassandraSparkBuild extends Build {
import Settings._
import sbtassembly.AssemblyPlugin
import sbtassembly.AssemblyKeys._
import sbtsparkpackage.SparkPackagePlugin
val namespace = "spark-cassandra-connector"
lazy val root = RootProject(
name = "root",
dir = file("."),
settings = rootSettings ++ Seq(Testing.cassandraServerClasspath := { "" }),
contains = Seq(embedded, connectorDistribution)
).disablePlugins(AssemblyPlugin, SparkPackagePlugin)
lazy val cassandraServerProject = Project(
id = "cassandra-server",
base = file(namespace),
settings = defaultSettings ++ sparkPackageSettings ++ Seq(
libraryDependencies ++= Seq(Artifacts.cassandraServer % "it", Artifacts.airlift),
Testing.cassandraServerClasspath := {
(fullClasspath in IntegrationTest).value.map(_.data.getAbsoluteFile).mkString(File.pathSeparator)
},
target := target.value / "cassandra-server",
sourceDirectory := baseDirectory.value / "cassandra-server",
resourceDirectory := baseDirectory.value / "cassandra-server"
)
) configs IntegrationTest
lazy val embedded = CrossScalaVersionsProject(
name = s"$namespace-embedded",
conf = defaultSettings ++ Seq(
libraryDependencies
++= Dependencies.embedded ++ Seq(
"org.scala-lang" % "scala-reflect" % scalaVersion.value,
"org.scala-lang" % "scala-compiler" % scalaVersion.value))
).disablePlugins(AssemblyPlugin, SparkPackagePlugin) configs IntegrationTest
/**
* Do not included shaded dependencies so they will not be listed in the Pom created for this
* project.
*
* Run the compile from the shaded project since we are no longer including shaded libs
*/
lazy val connectorDistribution = CrossScalaVersionsProject(
name = namespace,
conf = assembledSettings ++ Seq(
libraryDependencies ++= Dependencies.connectorDistribution ++ Seq(
"org.scala-lang" % "scala-reflect" % scalaVersion.value,
"org.scala-lang" % "scala-compiler" % scalaVersion.value % "test,it"),
//Use the assembly which contains all of the libs not just the shaded ones
assembly in spPackage := (assembly in shadedConnector).value,
assembly := (assembly in fullConnector).value,
//Use the shaded jar as our packageTarget
packageBin := {
val shaded = (assembly in shadedConnector).value
val targetName = target.value
val expected = target.value / s"$namespace-${version.value}.jar"
IO.move(shaded, expected)
val log = streams.value.log
log.info(s"""Shaded jar moved to $expected""".stripMargin)
expected
},
packagedArtifact in packageBin in Compile := {
(artifact.value, (assembly in shadedConnector).value)
},
sbt.Keys.`package` := packageBin.value)
++ Testing.pureCassandraSettings
).copy(dependencies = Seq(embedded % "test->test;it->it,test;")
) configs IntegrationTest
/** Because the distribution project has to mark the shaded jars as provided to remove them from
* the distribution dependencies we provide this additional project to build a fat jar which
* includes everything. The artifact produced by this project is unshaded while the assembly
* remains shaded.
*/
lazy val fullConnector = CrossScalaVersionsProject(
name = s"$namespace-unshaded",
conf = assembledSettings ++ Seq(
libraryDependencies ++= Dependencies.connectorAll
++ Dependencies.shaded
++ Seq(
"org.scala-lang" % "scala-reflect" % scalaVersion.value,
"org.scala-lang" % "scala-compiler" % scalaVersion.value % "test,it"),
target := target.value / "full"
)
++ Testing.pureCassandraSettings,
base = Some(namespace)
).copy(dependencies = Seq(embedded % "test->test;it->it,test")) configs IntegrationTest
lazy val shadedConnector = CrossScalaVersionsProject(
name = s"$namespace-shaded",
conf = assembledSettings ++ Seq(
libraryDependencies ++= Dependencies.connectorNonShaded
++ Dependencies.shaded
++ Seq(
"org.scala-lang" % "scala-reflect" % scalaVersion.value,
"org.scala-lang" % "scala-compiler" % scalaVersion.value % "test,it"),
target := target.value / "shaded",
test in assembly := {},
publishArtifact in (Compile, packageBin) := false)
++ Testing.pureCassandraSettings,
base = Some(namespace)
).copy(dependencies = Seq(embedded % "test->test;it->it,test;")
) configs IntegrationTest
def crossBuildPath(base: sbt.File, v: String): sbt.File = base / s"scala-$v" / "src"
/* templates */
def CrossScalaVersionsProject(name: String,
conf: Seq[Def.Setting[_]],
reliesOn: Seq[ClasspathDep[ProjectReference]] = Seq.empty,
base: Option[String] = None) =
Project(id = name, base = file(base.getOrElse(name)), dependencies = reliesOn, settings = conf ++ Seq(
unmanagedSourceDirectories in (Compile, packageBin) +=
crossBuildPath(baseDirectory.value, scalaBinaryVersion.value),
unmanagedSourceDirectories in (Compile, doc) +=
crossBuildPath(baseDirectory.value, scalaBinaryVersion.value),
unmanagedSourceDirectories in Compile +=
crossBuildPath(baseDirectory.value, scalaBinaryVersion.value)
))
def RootProject(
name: String,
dir: sbt.File, settings: =>
scala.Seq[sbt.Def.Setting[_]] = Seq.empty,
contains: Seq[ProjectReference]): Project =
Project(
id = name,
base = dir,
settings = parentSettings ++ settings,
aggregate = contains)
}
object Artifacts {
import Versions._
implicit class Exclude(module: ModuleID) {
def guavaExclude(): ModuleID =
module exclude("com.google.guava", "guava")
/**We will just include netty-all as a dependency **/
def nettyExclude(): ModuleID = module
.exclude("io.netty", "netty")
.exclude("io.netty", "netty-buffer")
.exclude("io.netty", "netty-codec")
.exclude("io.netty", "netty-common")
.exclude("io.netty", "netty-handler")
.exclude("io.netty", "netty-transport")
def glassfishExclude(): ModuleID = {
module
.exclude("org.glassfish.jersey.containers", "jersey-container-servlet-core")
.exclude("org.glassfish.jersey.containers", "jersey-container-servlet")
.exclude("org.glassfish.jersey.core", "jersey-client")
.exclude("org.glassfish.jersey.core", "jersey-common")
.exclude("org.glassfish.jersey.core", "jersey-server")
}
def sparkCoreExclusions(): ModuleID = module.guavaExclude().nettyExclude().glassfishExclude()
.exclude("commons-collections", "commons-collections")
.exclude("commons-beanutils", "commons-beanutils-core")
.exclude("commons-logging", "commons-logging")
.exclude("org.apache.curator", "curator-recipes")
def driverExclusions(): ModuleID = module.guavaExclude().nettyExclude()
.exclude("io.dropwizard.metrics", "metrics-core")
.exclude("org.slf4j", "slf4j-api")
def sparkExclusions(): ModuleID = module.sparkCoreExclusions()
.exclude("org.apache.spark", s"spark-core_$scalaBinary")
def logbackExclude(): ModuleID = module
.exclude("ch.qos.logback", "logback-classic")
.exclude("ch.qos.logback", "logback-core")
def replExclusions: ModuleID = module.guavaExclude()
.exclude("org.apache.spark", s"spark-bagel_$scalaBinary")
.exclude("org.apache.spark", s"spark-mllib_$scalaBinary")
.exclude("org.scala-lang", "scala-compiler")
}
val cassandraDriver = "com.yugabyte" % "cassandra-driver-core" % CassandraDriver driverExclusions() // ApacheV2
val cassandraDriverMapping = "com.yugabyte" % "cassandra-driver-mapping" % CassandraDriver driverExclusions() // ApacheV2
val commonsBeanUtils = "commons-beanutils" % "commons-beanutils" % CommonsBeanUtils exclude("commons-logging", "commons-logging") // ApacheV2
val config = "com.typesafe" % "config" % Config % "provided" // ApacheV2
val guava = "com.google.guava" % "guava" % Guava
val jodaC = "org.joda" % "joda-convert" % JodaC
val jodaT = "joda-time" % "joda-time" % JodaT
val lzf = "com.ning" % "compress-lzf" % Lzf % "provided"
val netty = "io.netty" % "netty-all" % Netty
val slf4jApi = "org.slf4j" % "slf4j-api" % Slf4j % "provided" // MIT
val jsr166e = "com.twitter" % "jsr166e" % JSR166e // Creative Commons
val airlift = "io.airlift" % "airline" % Airlift
val sparkCore = "org.apache.spark" %% "spark-core" % Spark sparkCoreExclusions() // ApacheV2
val sparkRepl = "org.apache.spark" %% "spark-repl" % Spark sparkExclusions() // ApacheV2
val sparkUnsafe = "org.apache.spark" %% "spark-unsafe" % Spark sparkExclusions() // ApacheV2
val sparkStreaming = "org.apache.spark" %% "spark-streaming" % Spark sparkExclusions() // ApacheV2
val sparkSql = "org.apache.spark" %% "spark-sql" % Spark sparkExclusions() // ApacheV2
val sparkCatalyst = "org.apache.spark" %% "spark-catalyst" % Spark sparkExclusions() // ApacheV2
val sparkHive = "org.apache.spark" %% "spark-hive" % Spark sparkExclusions() // ApacheV2
val cassandraServer = "org.apache.cassandra" % "cassandra-all" % Testing.cassandraTestVersion logbackExclude() exclude(org = "org.slf4j", name = "log4j-over-slf4j") // ApacheV2
object Metrics {
val metricsCore = "com.codahale.metrics" % "metrics-core" % CodaHaleMetrics % "provided"
val metricsJson = "com.codahale.metrics" % "metrics-json" % CodaHaleMetrics % "provided"
}
object Jetty {
val jettyServer = "org.eclipse.jetty" % "jetty-server" % SparkJetty % "provided"
val jettyServlet = "org.eclipse.jetty" % "jetty-servlet" % SparkJetty % "provided"
}
object Embedded {
val jopt = "net.sf.jopt-simple" % "jopt-simple" % JOpt
val sparkRepl = "org.apache.spark" %% "spark-repl" % Spark % "provided" replExclusions // ApacheV2
val snappy = "org.xerial.snappy" % "snappy-java" % "1.1.1.7"
val snakeYaml = "org.yaml" % "snakeyaml" % "1.16"
}
object Test {
val commonsIO = "commons-io" % "commons-io" % CommonsIO % "test,it" // ApacheV2
val scalaCheck = "org.scalacheck" %% "scalacheck" % ScalaCheck % "test,it" // BSD
val scalaMock = "org.scalamock" %% "scalamock" % ScalaMock % "test,it" // BSD
val scalaTest = "org.scalatest" %% "scalatest" % ScalaTest % "test,it" // ApacheV2
val scalactic = "org.scalactic" %% "scalactic" % Scalactic % "test,it" // ApacheV2
val sparkCoreT = "org.apache.spark" %% "spark-core" % Spark % "test,it" classifier "tests"
val sparkStreamingT = "org.apache.spark" %% "spark-streaming" % Spark % "test,it" classifier "tests"
val mockito = "org.mockito" % "mockito-all" % "1.10.19" % "test,it" // MIT
val junit = "junit" % "junit" % "4.11" % "test,it"
val junitInterface = "com.novocode" % "junit-interface" % "0.10" % "test,it"
val powerMock = "org.powermock" % "powermock-module-junit4" % "1.6.2" % "test,it" // ApacheV2
val powerMockMockito = "org.powermock" % "powermock-api-mockito" % "1.6.2" % "test,it" // ApacheV2
}
}
object Dependencies {
import Artifacts._
import BuildUtil._
val logging = Seq(slf4jApi)
val metrics = Seq(Metrics.metricsCore, Metrics.metricsJson)
val jetty = Seq(Jetty.jettyServer, Jetty.jettyServlet)
val testKit = Seq(
sparkRepl % "test,it",
Test.commonsIO,
Test.junit,
Test.junitInterface,
Test.scalaCheck,
Test.scalaMock,
Test.scalaTest,
Test.scalactic,
Test.sparkCoreT,
Test.sparkStreamingT,
Test.mockito,
Test.powerMock,
Test.powerMockMockito
)
val cassandra = Seq(cassandraDriver, cassandraDriverMapping)
val spark = Seq(sparkCore, sparkStreaming, sparkSql, sparkCatalyst, sparkHive, sparkUnsafe)
/**
* Dependencies which will be shaded in our distribution artifact and not listed on the
* distribution artifact's dependency list.
*/
val shaded = Seq(guava, cassandraDriver, cassandraDriverMapping)
/**
* This is the full dependency list required to build an assembly with all dependencies
* required to run the connector not listed as provided except for those which will
* be on the classpath because of Spark.
*/
val connectorAll = shaded ++ (testKit ++
metrics ++
jetty ++
logging ++
spark.map(_ % "provided") ++
Seq(commonsBeanUtils, jodaC, jodaT, lzf, netty, jsr166e)
).map(_ exclude(org = "org.slf4j", name = "log4j-over-slf4j"))
/**
* Mark the shaded dependencies as Provided, this removes them from the artifacts to be downloaded
* by build systems. This will avoid downloading a Cassandra Driver which does not have it's guava
* references shaded.
*/
val connectorDistribution = (connectorAll.toSet -- shaded.toSet).toSeq ++ shaded.map(_ % "provided")
/**
* When building the shaded jar we want the assembly task to ONLY include the shaded libs, to
* accomplish this we set all other dependencies as provided.
*/
val connectorNonShaded = (connectorAll.toSet -- shaded.toSet).toSeq.map { dep =>
dep.configurations match {
case Some(conf) => dep
case _ => dep % "provided"
}
}
val embedded = logging ++ spark ++ cassandra ++ Seq(
cassandraServer % "it,test" exclude("net.jpountz.lz4", "lz4"),
Embedded.jopt,
Embedded.sparkRepl,
Embedded.snappy,
Embedded.snakeYaml,
guava,
config).map(_ exclude(org = "org.slf4j", name = "log4j-over-slf4j"))
val documentationMappings = Seq(
DocumentationMapping(url(s"http://spark.apache.org/docs/${Versions.Spark}/api/scala/"),
sparkCore, sparkStreaming, sparkSql, sparkCatalyst, sparkHive
)
)
}