-
Notifications
You must be signed in to change notification settings - Fork 124
/
build.sbt
292 lines (277 loc) · 13.5 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
import akka.grpc.Dependencies
import akka.grpc.Dependencies.Versions.scala212
import akka.grpc.ProjectExtensions._
import akka.grpc.build.ReflectiveCodeGen
import sbt.Keys.scalaVersion
import com.geirsson.CiReleasePlugin
import com.typesafe.sbt.site.util.SiteHelpers
import com.jsuereth.sbtpgp.PgpKeys.publishSignedConfiguration
val akkaGrpcRuntimeName = "akka-grpc-runtime"
lazy val mkBatAssemblyTask = taskKey[File]("Create a Windows bat assembly")
// gradle plugin compatibility (avoid `+` in snapshot versions)
ThisBuild / dynverSeparator := "-"
// append -SNAPSHOT to version when isSnapshot
ThisBuild / dynverSonatypeSnapshots := true
val akkaGrpcCodegenId = "akka-grpc-codegen"
lazy val codegen = Project(id = akkaGrpcCodegenId, base = file("codegen"))
.enablePlugins(SbtTwirl, BuildInfoPlugin)
.enablePlugins(ReproducibleBuildsPlugin)
.disablePlugins(MimaPlugin, CiReleasePlugin)
.settings(Dependencies.codegen)
.settings(resolvers += Resolver.sbtPluginRepo("releases"))
.settings(
mkBatAssemblyTask := {
val file = assembly.value
Assemblies.mkBatAssembly(file)
},
buildInfoKeys ++= Seq[BuildInfoKey](organization, name, version, scalaVersion, sbtVersion),
buildInfoKeys += "runtimeArtifactName" -> akkaGrpcRuntimeName,
buildInfoKeys += "akkaVersion" -> Dependencies.Versions.akka,
buildInfoKeys += "akkaHttpVersion" -> Dependencies.Versions.akkaHttp,
buildInfoKeys += "grpcVersion" -> Dependencies.Versions.grpc,
buildInfoKeys += "googleProtobufVersion" -> Dependencies.Versions.googleProtobuf,
buildInfoPackage := "akka.grpc.gen",
(Compile / assembly / artifact) := {
val art = (Compile / assembly / artifact).value
art.withClassifier(Some("assembly"))
},
(assembly / mainClass) := Some("akka.grpc.gen.Main"),
(assembly / assemblyOption) := (assembly / assemblyOption).value.withPrependShellScript(
Some(sbtassembly.AssemblyPlugin.defaultUniversalScript(shebang = true))),
crossScalaVersions := Dependencies.Versions.CrossScalaForPlugin,
scalaVersion := Dependencies.Versions.CrossScalaForPlugin.head)
.settings(addArtifact((Compile / assembly / artifact), assembly))
.settings(addArtifact(Artifact(akkaGrpcCodegenId, "bat", "bat", "bat"), mkBatAssemblyTask))
lazy val runtime = Project(id = akkaGrpcRuntimeName, base = file("runtime"))
.settings(Dependencies.runtime)
.settings(VersionGenerator.settings)
.settings(
crossScalaVersions := Dependencies.Versions.CrossScalaForLib,
scalaVersion := Dependencies.Versions.CrossScalaForLib.head,
mimaFailOnNoPrevious := true,
mimaPreviousArtifacts :=
(if (scalaVersion.value.startsWith("2"))
previousStableVersion.value.map(v => Set(organization.value %% "akka-grpc-runtime" % v)).getOrElse(Set.empty)
else
Set.empty // FIXME no released Scala 3 artifacts yet, re-enable when there is
),
AutomaticModuleName.settings("akka.grpc.runtime"),
ReflectiveCodeGen.generatedLanguages := Seq("Scala"),
ReflectiveCodeGen.extraGenerators := Seq("ScalaMarshallersCodeGenerator"),
PB.protocVersion := Dependencies.Versions.googleProtobuf,
Test / PB.targets += (scalapb.gen() -> (Test / sourceManaged).value))
.enablePlugins(akka.grpc.build.ReflectiveCodeGen)
.enablePlugins(ReproducibleBuildsPlugin)
.disablePlugins(CiReleasePlugin)
/** This could be an independent project - or does upstream provide this already? didn't find it.. */
val akkaGrpcProtocPluginId = "akka-grpc-scalapb-protoc-plugin"
lazy val scalapbProtocPlugin = Project(id = akkaGrpcProtocPluginId, base = file("scalapb-protoc-plugin"))
.disablePlugins(MimaPlugin)
/** TODO we only really need to depend on scalapb */
.dependsOn(codegen)
.settings(
mkBatAssemblyTask := {
val file = assembly.value
Assemblies.mkBatAssembly(file)
},
(Compile / assembly / artifact) := {
val art = (Compile / assembly / artifact).value
art.withClassifier(Some("assembly"))
},
(assembly / mainClass) := Some("akka.grpc.scalapb.Main"),
(assembly / assemblyOption) := (assembly / assemblyOption).value.withPrependShellScript(
Some(sbtassembly.AssemblyPlugin.defaultUniversalScript(shebang = true))),
crossScalaVersions := Dependencies.Versions.CrossScalaForPlugin,
scalaVersion := Dependencies.Versions.CrossScalaForPlugin.head)
.settings(addArtifact((Compile / assembly / artifact), assembly))
.settings(addArtifact(Artifact(akkaGrpcProtocPluginId, "bat", "bat", "bat"), mkBatAssemblyTask))
.enablePlugins(ReproducibleBuildsPlugin)
.disablePlugins(CiReleasePlugin)
lazy val mavenPlugin = Project(id = "akka-grpc-maven-plugin", base = file("maven-plugin"))
.enablePlugins(akka.grpc.SbtMavenPlugin)
.enablePlugins(ReproducibleBuildsPlugin)
.disablePlugins(MimaPlugin, CiReleasePlugin)
.settings(Dependencies.mavenPlugin)
.settings(
publishMavenStyle := true,
crossPaths := false,
crossScalaVersions := Dependencies.Versions.CrossScalaForPlugin,
scalaVersion := Dependencies.Versions.CrossScalaForPlugin.head)
.dependsOn(codegen)
lazy val sbtPlugin = Project(id = "sbt-akka-grpc", base = file("sbt-plugin"))
.enablePlugins(SbtPlugin)
.enablePlugins(ReproducibleBuildsPlugin)
.disablePlugins(MimaPlugin, CiReleasePlugin)
.settings(Dependencies.sbtPlugin)
.settings(
/** And for scripted tests: */
scriptedLaunchOpts += ("-Dproject.version=" + version.value),
scriptedLaunchOpts ++= sys.props.collect { case (k @ "sbt.ivy.home", v) => s"-D$k=$v" }.toSeq,
scriptedDependencies := {
val p1 = publishLocal.value
val p2 = (codegen / publishLocal).value
val p3 = (runtime / publishLocal).value
val p4 = (interopTests / publishLocal).value
},
scriptedBufferLog := false,
crossScalaVersions := Dependencies.Versions.CrossScalaForPlugin,
scalaVersion := Dependencies.Versions.CrossScalaForPlugin.head,
publishSignedConfiguration := publishSignedConfiguration.value.withArtifacts(
// avoid publishing the plugin jar twice
publishSignedConfiguration.value.artifacts.filter(!_._1.name.contains("2.12_1.0"))))
.dependsOn(codegen)
lazy val interopTests = Project(id = "akka-grpc-interop-tests", base = file("interop-tests"))
.disablePlugins(MimaPlugin, CiReleasePlugin)
.settings(Dependencies.interopTests)
.settings(
crossScalaVersions := Dependencies.Versions.CrossScalaForLib,
scalaVersion := Dependencies.Versions.CrossScalaForLib.head)
.pluginTestingSettings
.settings(
// All io.grpc servers want to bind to port :8080
Test / parallelExecution := false,
ReflectiveCodeGen.generatedLanguages := Seq("Scala", "Java"),
ReflectiveCodeGen.extraGenerators := Seq("ScalaMarshallersCodeGenerator"),
ReflectiveCodeGen.codeGeneratorSettings ++= Seq("server_power_apis"),
// grpc-interop pulls in proto files with unfulfilled transitive deps it seems
// FIXME descriptor.proto is excluded because of EnumType issue https://github.com/scalapb/ScalaPB/issues/1557
PB.generate / excludeFilter := new SimpleFileFilter((f: File) =>
f.getAbsolutePath.endsWith("google/protobuf/descriptor.proto") ||
f.getParent.contains("envoy")),
PB.protocVersion := Dependencies.Versions.googleProtobuf,
// This project should use 'publish/skip := true', but we need
// to be able to `publishLocal` to run the interop tests as an
// sbt scripted test. At least skip scaladoc generation though.
Compile / doc := (Compile / doc / target).value)
.settings(inConfig(Test)(Seq(
reStart / mainClass := (Test / run / mainClass).value, {
import spray.revolver.Actions._
reStart := Def
.inputTask {
restartApp(
streams.value,
reLogTag.value,
thisProjectRef.value,
reForkOptions.value,
(reStart / mainClass).value,
(reStart / fullClasspath).value,
reStartArgs.value,
startArgsParser.parsed)
}
.dependsOn((Compile / products))
.evaluated
})))
lazy val benchmarks = Project(id = "benchmarks", base = file("benchmarks"))
.dependsOn(runtime)
.enablePlugins(JmhPlugin)
.disablePlugins(MimaPlugin, CiReleasePlugin)
.settings(
crossScalaVersions := Dependencies.Versions.CrossScalaForLib,
scalaVersion := Dependencies.Versions.CrossScalaForLib.head,
(publish / skip) := true)
// Config to allow only building scaladocs for runtime module but in/from the docs module
val AkkaGrpcRuntime = config("akkaGrpcRuntime")
lazy val docs = Project(id = "akka-grpc-docs", base = file("docs"))
// Make sure code generation is ran:
.dependsOn(pluginTesterScala)
.dependsOn(pluginTesterJava)
.enablePlugins(
SitePreviewPlugin,
AkkaParadoxPlugin,
ParadoxSitePlugin,
PreprocessPlugin,
PublishRsyncPlugin,
SiteScaladocPlugin)
.disablePlugins(MimaPlugin, CiReleasePlugin)
.settings(
name := "Akka gRPC",
publish / skip := true,
previewPath := (Paradox / siteSubdirName).value,
Preprocess / siteSubdirName := s"api/akka-grpc/${projectInfoVersion.value}",
Paradox / siteSubdirName := s"libraries/akka-grpc/${projectInfoVersion.value}",
// Make sure code generation is ran before paradox:
(Compile / paradox) := (Compile / paradox).dependsOn(Compile / compile).value,
paradoxGroups := Map("Language" -> Seq("Java", "Scala"), "Buildtool" -> Seq("sbt", "Gradle", "Maven")),
paradoxRoots := List("index.html", "quickstart-java/index.html", "quickstart-scala/index.html"),
Compile / paradoxProperties ++= Map(
"akka.version" -> Dependencies.Versions.akka,
"akka-http.version" -> Dependencies.Versions.akkaHttp,
"grpc.version" -> Dependencies.Versions.grpc,
"project.url" -> "https://doc.akka.io/libraries/akka-grpc/current/",
"canonical.base_url" -> "https://doc.akka.io/libraries/akka-grpc/current",
"scaladoc.scala.base_url" -> s"https://www.scala-lang.org/api/current/",
// Akka
"extref.akka.base_url" -> s"https://doc.akka.io/libraries/akka-core/${Dependencies.Versions.akkaBinary}/%s",
"scaladoc.akka.base_url" -> s"https://doc.akka.io/api/akka/${Dependencies.Versions.akkaBinary}",
"javadoc.akka.base_url" -> s"https://doc.akka.io/japi/akka/${Dependencies.Versions.akkaBinary}/",
// Akka HTTP
"extref.akka-http.base_url" -> s"https://doc.akka.io/libraries/akka-http/${Dependencies.Versions.akkaHttpBinary}/%s",
"scaladoc.akka.http.base_url" -> s"https://doc.akka.io/api/akka-http/${Dependencies.Versions.akkaHttpBinary}/",
"javadoc.akka.http.base_url" -> s"https://doc.akka.io/japi/akka-http/${Dependencies.Versions.akkaHttpBinary}/",
// Akka Management
"extref.akka-management.base_url" -> s"https://doc.akka.io/libraries/akka-management/current/%s",
// Akka gRPC
"scaladoc.akka.grpc.base_url" -> s"/${(Preprocess / siteSubdirName).value}/",
"javadoc.akka.grpc.base_url" -> "" // @apidoc links to Scaladoc
),
apidocRootPackage := "akka",
resolvers += Resolver.jcenterRepo,
publishRsyncArtifacts += makeSite.value -> "www/",
publishRsyncHost := "[email protected]")
.settings(
crossScalaVersions := Dependencies.Versions.CrossScalaForLib,
scalaVersion := Dependencies.Versions.CrossScalaForLib.head)
.settings(
// only the publish API docs for the runtime, inlined instead of using SiteScaladocPlugin.scaladocSettings
// to be able to reference the `projectInfoVersion` in the sub dir path
inConfig(AkkaGrpcRuntime)(
Seq(
siteSubdirName := s"api/akka-grpc/${projectInfoVersion.value}",
mappings := (runtime / Compile / packageDoc / mappings).value)) ++
SiteHelpers.addMappingsToSiteDir(AkkaGrpcRuntime / mappings, AkkaGrpcRuntime / siteSubdirName))
lazy val pluginTesterScala = Project(id = "akka-grpc-plugin-tester-scala", base = file("plugin-tester-scala"))
.disablePlugins(MimaPlugin, CiReleasePlugin)
.settings(Dependencies.pluginTester)
.settings(
(publish / skip) := true,
fork := true,
crossScalaVersions := Dependencies.Versions.CrossScalaForLib,
scalaVersion := Dependencies.Versions.CrossScalaForLib.head,
Test / parallelExecution := false,
ReflectiveCodeGen.codeGeneratorSettings ++= Seq("flat_package", "server_power_apis"))
.pluginTestingSettings
lazy val pluginTesterJava = Project(id = "akka-grpc-plugin-tester-java", base = file("plugin-tester-java"))
.disablePlugins(MimaPlugin, CiReleasePlugin)
.settings(Dependencies.pluginTester)
.settings(
(publish / skip) := true,
fork := true,
PB.protocVersion := Dependencies.Versions.googleProtobuf,
ReflectiveCodeGen.generatedLanguages := Seq("Java"),
crossScalaVersions := Dependencies.Versions.CrossScalaForLib,
scalaVersion := Dependencies.Versions.CrossScalaForLib.head,
Test / parallelExecution := false,
ReflectiveCodeGen.codeGeneratorSettings ++= Seq("server_power_apis"))
.pluginTestingSettings
lazy val root = Project(id = "akka-grpc", base = file("."))
.disablePlugins(SitePlugin, MimaPlugin, CiReleasePlugin)
.aggregate(
runtime,
codegen,
mavenPlugin,
sbtPlugin,
scalapbProtocPlugin,
interopTests,
pluginTesterScala,
pluginTesterJava,
benchmarks,
docs)
.settings(
(publish / skip) := true,
(Compile / headerCreate / unmanagedSources) := (baseDirectory.value / "project").**("*.scala").get,
// https://github.com/sbt/sbt/issues/3465
// Libs and plugins must share a version. The root project must use that
// version (and set the crossScalaVersions as empty list) so each sub-project
// can then decide which scalaVersion and crossCalaVersions they use.
crossScalaVersions := Nil,
scalaVersion := scala212)