-
Notifications
You must be signed in to change notification settings - Fork 86
/
build.sbt
436 lines (393 loc) · 14.6 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
import java.io.File
import Dependencies._
import com.typesafe.tools.mima.core.ProblemFilters
import com.typesafe.tools.mima.core._
import play.ws.AutomaticModuleName
import sbtassembly.AssemblyPlugin.autoImport._
import sbtassembly.MergeStrategy
//---------------------------------------------------------------
// Shading and Project Settings
//---------------------------------------------------------------
// Customise sbt-dynver's behaviour to make it work with tags which aren't v-prefixed
ThisBuild / dynverVTagPrefix := false
// Sanity-check: assert that version comes from a tag (e.g. not a too-shallow clone)
// https://github.com/dwijnand/sbt-dynver/#sanity-checking-the-version
Global / onLoad := (Global / onLoad).value.andThen { s =>
dynverAssertTagVersion.value
s
}
val javacSettings = Seq(
"--release",
"17",
"-Xlint:deprecation",
"-Xlint:unchecked"
)
val scalacOpts = Def.setting[Seq[String]] {
val sv = scalaBinaryVersion.value
val common = Seq(
"-release",
"17",
"-deprecation",
"-encoding",
"UTF-8",
"-feature",
"-unchecked"
)
if (sv == "3") {
common
} else {
common ++ Seq("-Ywarn-unused:imports", "-Xlint:nullary-unit", "-Xlint", "-Ywarn-dead-code")
}
}
val previousVersion: Option[String] = Some("3.0.0")
lazy val mimaSettings = Seq(
mimaPreviousArtifacts := previousVersion.map(organization.value %% moduleName.value % _).toSet,
mimaBinaryIssueFilters ++= Seq(
)
)
lazy val commonSettings = Def.settings(
organization := "org.playframework",
organizationName := "The Play Framework Project",
organizationHomepage := Some(url("https://playframework.com")),
homepage := Some(url("https://github.com/playframework/play-ws/")),
scmInfo := Some(ScmInfo(url("https://github.com/playframework/play-ws"), "[email protected]:playframework/play-ws.git")),
developers += Developer(
"playframework",
"The Play Framework Contributors",
url("https://github.com/playframework")
),
licenses := Seq("Apache-2.0" -> url("http://opensource.org/licenses/Apache-2.0")),
// To make use of Pekko snapshots uncomment following resolver:
// resolvers += Resolver.ApacheMavenSnapshotsRepo,
scalaVersion := scala213,
crossScalaVersions := Seq(scala213, scala3),
conflictWarning := {
if (scalaBinaryVersion.value == "3") {
ConflictWarning("warn", sbt.Level.Warn, false)
} else {
conflictWarning.value
}
},
scalacOptions ++= scalacOpts.value,
Compile / doc / scalacOptions ++= Seq(
"-Xfatal-warnings",
// Work around 2.12+ bug which prevents javadoc in nested java classes from compiling.
"-no-java-comments",
),
Compile / javacOptions ++= javacSettings,
Test / javacOptions ++= javacSettings,
headerLicense := {
Some(
HeaderLicense.Custom(
"""Copyright (C) from 2022 The Play Framework Contributors <https://github.com/playframework>, 2011-2021 Lightbend Inc. <https://www.lightbend.com>"""
)
)
}
)
lazy val shadedCommonSettings = Seq(
// scalaVersion := scala213,
// crossScalaVersions := Seq(scala213),
// No need to cross publish the shaded libraries
crossPaths := false,
autoScalaLibrary := false,
)
lazy val shadeAssemblySettings = commonSettings ++ shadedCommonSettings ++ Seq(
assembly / assemblyOption ~= (_.withIncludeScala(false)),
assembly / test := {},
assembly / assemblyJarName := {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((epoch, major)) =>
s"${name.value}.jar" // we are only shading java
case _ =>
sys.error("Cannot find valid scala version!")
}
},
)
val ahcMerge: MergeStrategy = CustomMergeStrategy("ahcMerge") { dependencies =>
Right(dependencies.map { f =>
val stream = () => {
val out = new java.io.ByteArrayOutputStream
val reader = new java.io.BufferedReader(new java.io.InputStreamReader(f.stream.apply()))
try {
reader.lines().forEach { line =>
// In AsyncHttpClientConfigDefaults.java, the shading renames the resource keys
// so we have to manually tweak the resource file to match.
val shadedline = line.replace("org.asynchttpclient", "play.shaded.ahc.org.asynchttpclient")
out.write(line.getBytes(IO.defaultCharset))
out.write(IO.Newline.getBytes(IO.defaultCharset))
out.write(shadedline.getBytes(IO.defaultCharset))
out.write(IO.Newline.getBytes(IO.defaultCharset))
}
} finally {
reader.close()
}
new java.io.ByteArrayInputStream(out.toByteArray)
}
JarEntry(target = f.target, stream = stream)
}.toVector)
}
import scala.xml.transform.RewriteRule
import scala.xml.transform.RuleTransformer
import scala.xml.Elem
import scala.xml.NodeSeq
import scala.xml.{ Node => XNode }
def dependenciesFilter(n: XNode) =
new RuleTransformer(new RewriteRule {
override def transform(n: XNode): NodeSeq =
n match {
case e: Elem if e.label == "dependencies" => NodeSeq.Empty
case other => other
}
}).transform(n).head
//---------------------------------------------------------------
// Shaded AsyncHttpClient implementation
//---------------------------------------------------------------
lazy val `shaded-asynchttpclient` = project
.in(file("shaded/asynchttpclient"))
.disablePlugins(MimaPlugin)
.settings(commonSettings)
.settings(shadeAssemblySettings)
.settings(
libraryDependencies ++= asyncHttpClient,
name := "shaded-asynchttpclient",
assembly / logLevel := Level.Error,
assembly / assemblyMergeStrategy := {
val NettyPropertiesPath = "META-INF" + File.separator + "io.netty.versions.properties"
val mergeStrategy: String => MergeStrategy = {
case NettyPropertiesPath =>
MergeStrategy.first
case ahcProperties if ahcProperties.endsWith("ahc-default.properties") =>
ahcMerge
case x =>
val oldStrategy = (assembly / assemblyMergeStrategy).value
oldStrategy(x)
}
mergeStrategy
},
// logLevel in assembly := Level.Debug,
assembly / assemblyShadeRules := Seq(
ShadeRule.rename("org.asynchttpclient.**" -> "play.shaded.ahc.@0").inAll,
ShadeRule.rename("io.netty.**" -> "play.shaded.ahc.@0").inAll,
ShadeRule.rename("javassist.**" -> "play.shaded.ahc.@0").inAll,
ShadeRule // asynchttpclient 2.x depends on netty-reactive-streams 2.x (v3 drops it, see async-http-client#1843 + #1819)
.rename("com.typesafe.netty.**" -> "play.shaded.ahc.@0")
.inAll,
ShadeRule.rename("javax.activation.**" -> "play.shaded.ahc.@0").inAll,
ShadeRule.rename("com.sun.activation.**" -> "play.shaded.ahc.@0").inAll,
ShadeRule.zap("org.reactivestreams.**").inAll,
ShadeRule.zap("org.slf4j.**").inAll
),
// https://stackoverflow.com/questions/24807875/how-to-remove-projectdependencies-from-pom
// Remove dependencies from the POM because we have a FAT jar here.
makePomConfiguration := makePomConfiguration.value.withProcess(process = dependenciesFilter),
// ivyXML := <dependencies></dependencies>,
// ivyLoggingLevel := UpdateLogging.Full,
// logLevel := Level.Debug,
assembly / assemblyOption := (assembly / assemblyOption).value.withIncludeBin(false).withIncludeScala(false),
Compile / packageBin := assembly.value
)
//---------------------------------------------------------------
// Shaded oauth
//---------------------------------------------------------------
lazy val `shaded-oauth` = project
.in(file("shaded/oauth"))
.disablePlugins(MimaPlugin)
.settings(commonSettings)
.settings(shadeAssemblySettings)
.settings(
libraryDependencies ++= oauth,
name := "shaded-oauth",
// logLevel in assembly := Level.Debug,
assembly / assemblyShadeRules := Seq(
ShadeRule.rename("oauth.**" -> "play.shaded.oauth.@0").inAll,
ShadeRule.rename("org.apache.commons.**" -> "play.shaded.oauth.@0").inAll
),
// https://stackoverflow.com/questions/24807875/how-to-remove-projectdependencies-from-pom
// Remove dependencies from the POM because we have a FAT jar here.
makePomConfiguration := makePomConfiguration.value.withProcess(process = dependenciesFilter),
assembly / assemblyOption := (assembly / assemblyOption).value.withIncludeBin(false).withIncludeScala(false),
Compile / packageBin := assembly.value
)
// Make the shaded version of AHC available downstream
val shadedAhcSettings = Seq(
Compile / unmanagedJars += (`shaded-asynchttpclient` / Compile / packageBin).value
)
val shadedOAuthSettings = Seq(
Compile / unmanagedJars += (`shaded-oauth` / Compile / packageBin).value
)
//---------------------------------------------------------------
// Shaded aggregate project
//---------------------------------------------------------------
lazy val shaded = Project(id = "shaded", base = file("shaded"))
.aggregate(
`shaded-asynchttpclient`,
`shaded-oauth`
)
.disablePlugins(sbtassembly.AssemblyPlugin, HeaderPlugin, MimaPlugin)
.settings(
publish / skip := true,
commonSettings,
shadedCommonSettings,
)
//---------------------------------------------------------------
// WS API
//---------------------------------------------------------------
// WS API, no play dependencies
lazy val `play-ws-standalone` = project
.in(file("play-ws-standalone"))
.settings(commonSettings)
.settings(mimaSettings)
.settings(libraryDependencies ++= standaloneApiWSDependencies)
.settings(AutomaticModuleName.settings("play.ws.standalone"))
.disablePlugins(sbtassembly.AssemblyPlugin)
//---------------------------------------------------------------
// Shaded AsyncHttpClient implementation of WS
//---------------------------------------------------------------
def addShadedDeps(deps: Seq[xml.Node], node: xml.Node): xml.Node = {
node match {
case elem: xml.Elem =>
val child = if (elem.label == "dependencies") {
elem.child ++ deps
} else {
elem.child.map(addShadedDeps(deps, _))
}
xml.Elem(elem.prefix, elem.label, elem.attributes, elem.scope, false, child: _*)
case _ =>
node
}
}
// Standalone implementation using AsyncHttpClient
lazy val `play-ahc-ws-standalone` = project
.in(file("play-ahc-ws-standalone"))
.settings(
commonSettings ++ shadedAhcSettings ++ shadedOAuthSettings ++ Seq(
Test / fork := true,
Test / testOptions := Seq(Tests.Argument(TestFrameworks.JUnit, "-a", "-v")),
libraryDependencies ++= standaloneAhcWSDependencies,
// This will not work if you do a publishLocal, because that uses ivy...
pomPostProcess := { (node: xml.Node) =>
addShadedDeps(
List(
<dependency>
<groupId>org.playframework</groupId>
<artifactId>shaded-asynchttpclient</artifactId>
<version>{version.value}</version>
</dependency>,
<dependency>
<groupId>org.playframework</groupId>
<artifactId>shaded-oauth</artifactId>
<version>{version.value}</version>
</dependency>
),
node
)
}
)
)
.settings(mimaSettings)
.settings(AutomaticModuleName.settings("play.ws.standalone.ahc"))
.dependsOn(
`play-ws-standalone`
)
.disablePlugins(sbtassembly.AssemblyPlugin)
//---------------------------------------------------------------
// JSON Readables and Writables
//---------------------------------------------------------------
lazy val `play-ws-standalone-json` = project
.in(file("play-ws-standalone-json"))
.settings(commonSettings)
.settings(mimaSettings)
.settings(
Test / fork := true,
Test / testOptions := Seq(Tests.Argument(TestFrameworks.JUnit, "-a", "-v")),
libraryDependencies ++= standaloneAhcWSJsonDependencies
)
.settings(AutomaticModuleName.settings("play.ws.standalone.json"))
.dependsOn(
`play-ws-standalone`
)
.disablePlugins(sbtassembly.AssemblyPlugin)
//---------------------------------------------------------------
// XML Readables and Writables
//---------------------------------------------------------------
lazy val `play-ws-standalone-xml` = project
.in(file("play-ws-standalone-xml"))
.settings(commonSettings)
.settings(mimaSettings)
.settings(
Test / fork := true,
Test / testOptions := Seq(Tests.Argument(TestFrameworks.JUnit, "-a", "-v")),
libraryDependencies ++= standaloneAhcWSXMLDependencies
)
.settings(AutomaticModuleName.settings("play.ws.standalone.xml"))
.dependsOn(
`play-ws-standalone`
)
.disablePlugins(sbtassembly.AssemblyPlugin)
//---------------------------------------------------------------
// Integration Tests
//---------------------------------------------------------------
lazy val `integration-tests` = project
.in(file("integration-tests"))
.disablePlugins(MimaPlugin, sbtassembly.AssemblyPlugin)
.settings(commonSettings)
.settings(publish / skip := true)
.settings(
Test / fork := true,
concurrentRestrictions += Tags.limitAll(1), // only one integration test at a time
Test / testOptions := Seq(Tests.Argument(TestFrameworks.JUnit, "-a", "-v")),
libraryDependencies ++= backendServerTestDependencies ++ testDependencies,
)
.settings(shadedAhcSettings)
.settings(shadedOAuthSettings)
.dependsOn(
`play-ahc-ws-standalone`,
`play-ws-standalone-json`,
`play-ws-standalone-xml`
)
//---------------------------------------------------------------
// Benchmarks (run manually)
//---------------------------------------------------------------
lazy val bench = project
.in(file("bench"))
.enablePlugins(JmhPlugin)
.disablePlugins(MimaPlugin)
.dependsOn(
`play-ws-standalone`,
`play-ws-standalone-json`,
`play-ws-standalone-xml`,
`play-ahc-ws-standalone`
)
.settings(commonSettings)
.settings(Compile / doc / scalacOptions -= "-Xfatal-warnings")
.settings(publish / skip := true)
//---------------------------------------------------------------
// Root Project
//---------------------------------------------------------------
lazy val root = project
.in(file("."))
.disablePlugins(MimaPlugin, sbtassembly.AssemblyPlugin)
.settings(
name := "play-ws-standalone-root",
)
.settings(commonSettings)
.settings(publish / skip := true)
.settings(crossScalaVersions := Seq(scala213))
.aggregate(
`shaded`,
`play-ws-standalone`,
`play-ws-standalone-json`,
`play-ws-standalone-xml`,
`play-ahc-ws-standalone`,
`integration-tests`,
bench
)
addCommandAlias(
"validateCode",
List(
"headerCheckAll",
"scalafmtSbtCheck",
"scalafmtCheckAll",
).mkString(";")
)