-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathbuild.sbt
238 lines (215 loc) · 6.52 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
import Dependencies.*
import IntellijIdeaScalaVersion.*
import ScalaVersions.*
import commandmatrix.Dimension
import sbt.*
import sbt.Keys.*
import sbt.internal.ProjectMatrix
ThisBuild / scalaVersion := scala213
// {{{ Configure Intellij Idea
// Scala Version in IDE
val intellijIdeaScalaVersion = IntellijIdeaScalaVersion(scala213)
// ???
Global / excludeLintKeys += ideSkipProject
// }}}
/** Early Semver
*
* Given a version number major.minor.patch, you MUST increment the:
* - [[major]] version if backward [[binary]] compatibility is broken,
* - [[minor]] version if backward [[source]] compatibility is broken, and
* - [[patch]] version to signal neither [[binary]] nor [[source]] incompatibility. When the [[major]] version is
* [[0]], a [[minor]] version increment *MAY* contain both [[source]] and [[binary]] breakages, but a [[patch]]
* version increment *MUST* remain [[binary]] compatible.
*
* Links
* - https://www.scala-lang.org/blog/2021/02/16/preventing-version-conflicts-with-versionscheme.html
* - https://docs.scala-lang.org/overviews/core/binary-compatibility-for-library-authors.html#versioning-scheme---communicating-compatibility-breakages
*/
ThisBuild / versionScheme := Some("early-semver")
ThisBuild / libraryDependencies ++= Seq(
scalatest,
mockito
)
// format: off
/** ---------------------
* Modules
* -------
*/
// format: on
lazy val api = (projectMatrix in file("modules/api"))
.dependsOn(simpleNettyEchoWebsocketServer % Test)
.settings(
name := "websocket-api",
commonOptions,
libraryDependencies += scalatestplus(scalaVersion.value)
)
.jvmOnly(intellijIdeaScalaVersion)
lazy val backendNetty = (projectMatrix in file("modules/backend-netty"))
.dependsOn(api % "test->test;compile->compile")
.settings(
name := "websocket-backend-netty",
commonOptions,
libraryDependencies ++= Seq(
nettyAll,
nettyHttp,
scalaStm,
slf4jApi
)
)
.jvmOnly(intellijIdeaScalaVersion)
lazy val backendAkka = (projectMatrix in file("modules/backend-akka"))
.dependsOn(api % "test->test;compile->compile")
.settings(
name := "websocket-backend-akka",
commonOptions,
libraryDependencies ++= Seq(
akkaHttp(scalaVersion.value).cross(CrossVersion.binary),
akkaStream(scalaVersion.value).cross(CrossVersion.binary)
),
includeScala211PlusFolders
)
.jvmOnly(intellijIdeaScalaVersion)
lazy val backendPekko = (projectMatrix in file("modules/backend-pekko"))
.dependsOn(api % "test->test;compile->compile")
.settings(
name := "websocket-backend-pekko",
commonOptions,
libraryDependencies ++= Seq(
pekkoHttp,
pekkoStream
)
)
.jvmOnly(intellijIdeaScalaVersion, excluding = { case `scala211` => })
lazy val backendJdkHttpClient = (projectMatrix in file("modules/backend-jdk-http-client"))
.dependsOn(api % "test->test;compile->compile")
.settings(
name := "websocket-backend-jdk-http-client",
commonOptions,
libraryDependencies ++= Seq(
slf4jApi
)
)
.jvmOnly(intellijIdeaScalaVersion)
lazy val serdeAvro4s = (projectMatrix in file("modules/serde-avro4s"))
.dependsOn(api % "test->test;compile->compile")
.settings(
name := "websocket-serde-avro4s",
commonOptions,
libraryDependencies ++= Seq(
avro4s(scalaVersion.value)
)
)
.jvmOnly(intellijIdeaScalaVersion, excluding = { case `scala211` | `scala3` => })
lazy val serdeJsoniterScala = (projectMatrix in file("modules/serde-jsoniter"))
.dependsOn(api % "test->test;compile->compile")
.settings(
name := "websocket-serde-avro4s",
commonOptions,
libraryDependencies ++= Seq(
jsoniterScala(scalaVersion.value).core % Compile,
jsoniterScala(scalaVersion.value).macros % Test
)
)
.jvmOnly(intellijIdeaScalaVersion)
// TODO: can be written entirely in the lowest scala version or in java so we don't need to rebuild it for other
// scala versions as it only needed in tests
lazy val simpleNettyEchoWebsocketServer = (projectMatrix in file("modules/simple-netty-websocket-echo-server"))
.settings(
name := "simple-netty-websocket-echo-server",
libraryDependencies ++= Seq(
nettyAll,
nettyHttp,
log4j2Api,
log4j2Core,
bcCore,
bcPkix
),
disablePublishing
)
.jvmPlatform(scalaVersions = allScalaVersions())
// format: off
/** ---------------------
* Root
* ----
*/
// format: on
lazy val matrices = Seq(
api,
backendNetty,
backendJdkHttpClient,
backendAkka,
backendPekko,
serdeAvro4s,
serdeJsoniterScala
)
lazy val root = (project in file("."))
.aggregate(
matrices.flatMap(_.projectRefs): _*
)
.settings(
name := "websocket-root",
disablePublishing
)
.settings()
// format: off
/** ---------------------
* Custom Matrix Commands
* ---------------
*/
// format: on
inThisBuild(
Seq(
// sbt-commandmatrix
commands ++= CrossCommand.all(
Seq(
"clean",
"test",
"publishSigned"
),
matrices = matrices,
dimensions = Seq(
Dimension.scala("2.13", fullFor3 = false),
Dimension.platform()
)
)
)
)
val scalaVersionDimension = Seq("2_11", "2_12", "2_13", "3_3")
addCommandAlias("publishMatrix", scalaVersionDimension.map(v => s";publishSigned-$v-jvm").mkString)
// format: off
/** ---------------------
* Utilities
* ---------
*/
// format: on
def specificFolder(base: File, suffix: String): Seq[File] = Seq(base / "main" / s"scala-$suffix")
lazy val projectsToAggregate: String => List[ProjectMatrix] = {
val projects = List(api, backendNetty, backendJdkHttpClient, backendAkka)
scalaVersion =>
CrossVersion.partialVersion(scalaVersion) match {
case Some((2, 11)) => projects :+ backendPekko
case _ => projects
}
}
val disablePublishing = Seq[Setting[_]](
publishArtifact := false,
publish / skip := true
)
val includeScala211PlusFolders = Seq[Setting[_]](
Compile / unmanagedSourceDirectories ++= {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 11)) => Nil
case _ => specificFolder(sourceDirectory.value, "2.11+")
}
},
Test / unmanagedSourceDirectories ++= {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 11)) => Nil
case _ => specificFolder(sourceDirectory.value, "2.11+")
}
}
)
lazy val commonOptions = Seq[Setting[_]](
Compile / doc / scalacOptions ++= Seq("-groups", "-implicits", "-no-link-warnings"),
scalacOptions := ScalaCompilerOptions(scalaVersion.value)
)