-
Notifications
You must be signed in to change notification settings - Fork 20
/
build.sbt
164 lines (158 loc) · 5.57 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
import sbt._
import Keys._
$if(DataflowFlexTemplate.truthy)$
import com.typesafe.sbt.packager.docker._
import scala.sys.process._
import complete.DefaultParsers._
$endif$
val scioVersion = "0.11.0"
val beamVersion = "2.32.0"
$if(FlinkRunner.truthy)$
val flinkVersion = "1.13.1"
$endif$
$if(SparkRunner.truthy)$
val sparkVersion = "3.1.2"
$endif$
lazy val commonSettings = Def.settings(
organization := "$organization$",
// Semantic versioning http://semver.org/
version := "0.1.0-SNAPSHOT",
$if(FlinkRunner.truthy || SparkRunner.truthy)$
// scala-steward:off
scalaVersion := "2.12.13",
// scala-steward:on
$else$
scalaVersion := "2.13.3",
$endif$
$if(DataflowRunner.truthy)$
resolvers += "confluent" at "https://packages.confluent.io/maven/",
$endif$
scalacOptions ++= Seq("-target:jvm-1.8",
"-deprecation",
"-feature",
"-unchecked"),
javacOptions ++= Seq("-source", "1.8", "-target", "1.8")
)
lazy val root: Project = project
.in(file("."))
.settings(commonSettings)
$if(DataflowFlexTemplate.truthy)$
.settings(assemblySettings)
$endif$
.settings(
name := "$name;format="lower,hyphen"$",
description := "$name$",
publish / skip := true,
run / classLoaderLayeringStrategy := ClassLoaderLayeringStrategy.Flat,
libraryDependencies ++= Seq(
"com.spotify" %% "scio-core" % scioVersion,
"com.spotify" %% "scio-test" % scioVersion % Test,
"org.apache.beam" % "beam-runners-direct-java" % beamVersion,
$if(DataflowRunner.truthy || DataflowFlexTemplate.truthy)$
"org.apache.beam" % "beam-runners-google-cloud-dataflow-java" % beamVersion,
$endif$
$if(FlinkRunner.truthy)$
"org.apache.beam" % "beam-runners-flink-1.10" % beamVersion excludeAll (
ExclusionRule("com.twitter", "chill_2.11"),
ExclusionRule("org.apache.flink", "flink-clients_2.11"),
ExclusionRule("org.apache.flink", "flink-runtime_2.11"),
ExclusionRule("org.apache.flink", "flink-streaming-java_2.11"),
ExclusionRule("org.apache.flink", "flink-optimizer_2.11")
),
"org.apache.flink" %% "flink-clients" % flinkVersion,
"org.apache.flink" %% "flink-runtime" % flinkVersion,
"org.apache.flink" %% "flink-streaming-java" % flinkVersion,
"org.apache.flink" %% "flink-optimizer" % flinkVersion,
$endif$
$if(SparkRunner.truthy)$
"org.apache.beam" % "beam-runners-spark" % beamVersion exclude (
"com.fasterxml.jackson.module", "jackson-module-scala_2.11"
),
"org.apache.spark" %% "spark-core" % sparkVersion,
"org.apache.spark" %% "spark-streaming" % sparkVersion,
$endif$
"org.slf4j" % "slf4j-simple" % "1.7.32"
)
)
.enablePlugins(JavaAppPackaging)
lazy val repl: Project = project
.in(file(".repl"))
.settings(commonSettings)
.settings(
name := "repl",
description := "Scio REPL for $name$",
libraryDependencies ++= Seq(
"com.spotify" %% "scio-repl" % scioVersion
),
Compile / mainClass := Some("com.spotify.scio.repl.ScioShell"),
publish / skip := true
)
.dependsOn(root)
$if(DataflowFlexTemplate.truthy)$
lazy val gcpProject = settingKey[String]("GCP Project")
lazy val gcpRegion = settingKey[String]("GCP region")
lazy val createFlextTemplate = inputKey[Unit]("create DataflowFlexTemplate")
lazy val runFlextTemplate = inputKey[Unit]("run DataflowFlexTemplate")
lazy val assemblySettings = Def.settings(
gcpProject := "",
gcpRegion := "",
assembly / test := {},
assembly / assemblyJarName := "flex-wordcount.jar",
assembly / assemblyMergeStrategy ~= { old =>
{
case s if s.endsWith(".properties") => MergeStrategy.filterDistinctLines
case s if s.endsWith("public-suffix-list.txt") =>
MergeStrategy.filterDistinctLines
case s if s.endsWith(".class") => MergeStrategy.last
case s if s.endsWith(".proto") => MergeStrategy.last
case s if s.endsWith("reflection-config.json") => MergeStrategy.rename
case s => old(s)
}
},
Universal / mappings := {
val fatJar = (Compile / assembly).value
val filtered = (Universal / mappings).value.filter {
case (_, name) => !name.endsWith(".jar")
}
filtered :+ (fatJar -> (s"lib/\${fatJar.getName}"))
},
scriptClasspath := Seq((assembly / jarName).value),
Docker / packageName := s"gcr.io/\${gcpProject.value}/dataflow/templates/DataflowFlexTemplate",
Docker / dockerCommands := Seq(
Cmd(
"FROM",
"gcr.io/dataflow-templates-base/java11-template-launcher-base:latest"
),
Cmd(
"ENV",
"FLEX_TEMPLATE_JAVA_MAIN_CLASS",
(assembly / mainClass).value.getOrElse("")
),
Cmd(
"ENV",
"FLEX_TEMPLATE_JAVA_CLASSPATH",
s"/template/\${(assembly / assemblyJarName).value}"
),
ExecCmd(
"COPY",
s"1/opt/docker/lib/\${(assembly / assemblyJarName).value}",
"\${FLEX_TEMPLATE_JAVA_CLASSPATH}"
)
),
createFlextTemplate := {
val _ = (Docker / publish).value
s"""gcloud beta dataflow DataflowFlexTemplate build
gs://\${gcpProject.value}/dataflow/templates/\${name.value}.json
--image \${dockerAlias.value}
--sdk-language JAVA
--metadata-file metadata.json""" !
},
runFlextTemplate := {
val parameters = spaceDelimited("<arg>").parsed
s"""gcloud beta dataflow DataflowFlexTemplate run \${name.value}
--template-file-gcs-location gs://\${gcpProject.value}/dataflow/templates/\${name.value}.json
--region=\${gcpRegion.value}
--parameters \${parameters.mkString(",")}""" !
}
)
$endif$