forked from zio/zio-json
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sbt
353 lines (328 loc) · 13 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
import BuildHelper._
import explicitdeps.ExplicitDepsPlugin.autoImport.moduleFilterRemoveValue
import sbtcrossproject.CrossPlugin.autoImport.crossProject
inThisBuild(
List(
organization := "dev.zio",
homepage := Some(url("https://zio.github.io/zio-json/")),
licenses := List("Apache-2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0")),
developers := List(
Developer(
"jdegoes",
"John De Goes",
"john@degoes.net",
url("http://degoes.net")
)
)
)
)
addCommandAlias("check", "; scalafmtSbtCheck; scalafmtCheckAll")
addCommandAlias("fmt", "all scalafmtSbt scalafmtAll")
addCommandAlias("fmtCheck", "all scalafmtSbtCheck scalafmtCheckAll")
addCommandAlias("prepare", "fmt")
addCommandAlias(
"testJVM",
"zioJsonJVM/test; zioJsonYaml/test; zioJsonMacrosJVM/test; zioJsonInteropHttp4s/test; zioJsonInteropScalaz7xJVM/test; zioJsonInteropScalaz7xJS/test; zioJsonInteropRefinedJVM/test; zioJsonInteropRefinedJS/test"
)
addCommandAlias(
"testJVMDotty",
"zioJsonJVM/test"
)
addCommandAlias("testJS", "zioJsonJS/test")
val zioVersion = "1.0.13"
lazy val root = project
.in(file("."))
.settings(
publish / skip := true,
unusedCompileDependenciesFilter -= moduleFilter("org.scala-js", "scalajs-library")
)
.aggregate(
docs,
zioJsonJVM,
zioJsonJS,
zioJsonYaml,
zioJsonMacrosJVM,
zioJsonMacrosJS,
zioJsonInteropHttp4s,
zioJsonInteropRefined.js,
zioJsonInteropRefined.jvm,
zioJsonInteropScalaz7x.js,
zioJsonInteropScalaz7x.jvm
)
val circeVersion = "0.14.1"
lazy val zioJson = crossProject(JSPlatform, JVMPlatform)
.in(file("zio-json"))
.settings(stdSettings("zio-json"))
.settings(crossProjectSettings)
.settings(buildInfoSettings("zio.json"))
.enablePlugins(NeoJmhPlugin)
.settings(
scalacOptions -= "-Xfatal-warnings", // not quite ready.
// as per @fommil, optimization slows things down.
scalacOptions -= "-opt:l:inline",
scalacOptions -= "-opt-inline-from:zio.internal.**",
//scalaVersion := ScalaDotty,
libraryDependencies ++= Seq(
"dev.zio" %%% "zio" % zioVersion,
"dev.zio" %%% "zio-streams" % zioVersion,
"org.scala-lang.modules" %%% "scala-collection-compat" % "2.5.0",
"dev.zio" %%% "zio-test" % zioVersion % "test",
"dev.zio" %%% "zio-test-sbt" % zioVersion % "test",
"io.circe" %%% "circe-core" % circeVersion % "test",
"io.circe" %%% "circe-generic" % circeVersion % "test",
"io.circe" %%% "circe-parser" % circeVersion % "test"
),
// scala version specific depenendies
libraryDependencies ++= {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((3, _)) =>
Vector(
"com.softwaremill.magnolia1_3" %%% "magnolia" % "1.1.0"
)
case _ =>
Vector(
"org.scala-lang" % "scala-reflect" % scalaVersion.value % Provided,
"com.propensive" %%% "magnolia" % "0.17.0",
"io.circe" %%% "circe-generic-extras" % circeVersion % "test",
"com.typesafe.play" %%% "play-json" % "2.9.2" % "test",
"com.github.plokhotnyuk.jsoniter-scala" %%% "jsoniter-scala-core" % "2.12.3" % "test",
"com.github.plokhotnyuk.jsoniter-scala" %%% "jsoniter-scala-macros" % "2.12.3" % "test"
)
}
},
Compile / sourceGenerators += Def.task {
val dir = (Compile / sourceManaged).value
val file = dir / "zio" / "json" / "GeneratedTupleDecoders.scala"
val decoders = (1 to 22).map { i =>
val tparams = (1 to i).map(p => s"A$p").mkString(", ")
val implicits = (1 to i).map(p => s"A$p: JsonDecoder[A$p]").mkString(", ")
val work = (1 to i)
.map(p => s"val a$p = A$p.unsafeDecode(trace :+ traces($p), in)")
.mkString("\n Lexer.char(trace, in, ',')\n ")
val returns = (1 to i).map(p => s"a$p").mkString(", ")
s"""implicit def tuple$i[$tparams](implicit $implicits): JsonDecoder[Tuple$i[$tparams]] =
| new JsonDecoder[Tuple$i[$tparams]] {
| val traces: Array[JsonError] = (0 to $i).map(JsonError.ArrayAccess(_)).toArray
| def unsafeDecode(trace: List[JsonError], in: RetractReader): Tuple$i[$tparams] = {
| Lexer.char(trace, in, '[')
| $work
| Lexer.char(trace, in, ']')
| Tuple$i($returns)
| }
| }""".stripMargin
}
IO.write(
file,
s"""package zio.json
|
|import zio.json.internal._
|
|private[json] trait GeneratedTupleDecoders { this: JsonDecoder.type =>
| ${decoders.mkString("\n\n ")}
|}""".stripMargin
)
Seq(file)
}.taskValue,
Compile / sourceGenerators += Def.task {
val dir = (Compile / sourceManaged).value
val file = dir / "zio" / "json" / "GeneratedTupleEncoders.scala"
val encoders = (1 to 22).map { i =>
val tparams = (1 to i).map(p => s"A$p").mkString(", ")
val implicits = (1 to i).map(p => s"A$p: JsonEncoder[A$p]").mkString(", ")
val work = (1 to i)
.map(p => s"A$p.unsafeEncode(t._$p, indent, out)")
.mkString("\n if (indent.isEmpty) out.write(',') else out.write(\", \")\n ")
s"""implicit def tuple$i[$tparams](implicit $implicits): JsonEncoder[Tuple$i[$tparams]] =
| new JsonEncoder[Tuple$i[$tparams]] {
| def unsafeEncode(t: Tuple$i[$tparams], indent: Option[Int], out: internal.Write): Unit = {
| out.write('[')
| $work
| out.write(']')
| }
| }""".stripMargin
}
IO.write(
file,
s"""package zio.json
|
|private[json] trait GeneratedTupleEncoders { this: JsonEncoder.type =>
| ${encoders.mkString("\n\n ")}
|}""".stripMargin
)
Seq(file)
}.taskValue,
Compile / sourceGenerators += Def.task {
val dir = (Compile / sourceManaged).value
val file = dir / "zio" / "json" / "GeneratedTupleCodecs.scala"
val codecs = (1 to 22).map { i =>
val tparams = (1 to i).map(p => s"A$p").mkString(", ")
val implicits = (1 to i).map(p => s"A$p: JsonCodec[A$p]").mkString(", ")
s"""implicit def tuple$i[$tparams](implicit $implicits): JsonCodec[Tuple$i[$tparams]] =
| JsonCodec(JsonEncoder.tuple$i, JsonDecoder.tuple$i)""".stripMargin
}
IO.write(
file,
s"""package zio.json
|
|private[json] trait GeneratedTupleCodecs { this: JsonCodec.type =>
| ${codecs.mkString("\n\n ")}
|}""".stripMargin
)
Seq(file)
}.taskValue,
inConfig(Jmh)(org.scalafmt.sbt.ScalafmtPlugin.scalafmtConfigSettings)
)
.settings(testFrameworks += new TestFramework("zio.test.sbt.ZTestFramework"))
.jsSettings(
libraryDependencies ++= Seq(
"io.github.cquiroz" %%% "scala-java-time" % "2.3.0",
"io.github.cquiroz" %%% "scala-java-time-tzdb" % "2.3.0"
)
)
.jvmSettings(
libraryDependencies ++= {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((3, _)) =>
Vector(
"org.typelevel" %% "jawn-ast" % "1.3.2" % "test"
)
case _ =>
Seq(
"ai.x" %% "play-json-extensions" % "0.42.0" % "test",
"org.typelevel" %% "jawn-ast" % "1.3.2" % "test"
)
}
}
)
.enablePlugins(BuildInfoPlugin)
lazy val zioJsonJS = zioJson.js
.settings(
scalaJSUseMainModuleInitializer := true,
testFrameworks += new TestFramework("zio.test.sbt.ZTestFramework"),
coverageEnabled := false
)
lazy val zioJsonJVM = zioJson.jvm
lazy val zioJsonYaml = project
.in(file("zio-json-yaml"))
.settings(stdSettings("zio-json-yaml"))
.settings(buildInfoSettings("zio.json.yaml"))
.settings(
libraryDependencies ++= Seq(
"org.yaml" % "snakeyaml" % "1.30",
"dev.zio" %% "zio" % zioVersion,
"dev.zio" %% "zio-test" % zioVersion % "test",
"dev.zio" %% "zio-test-sbt" % zioVersion % "test"
),
testFrameworks += new TestFramework("zio.test.sbt.ZTestFramework")
)
.dependsOn(zioJsonJVM)
.enablePlugins(BuildInfoPlugin)
lazy val zioJsonMacros = crossProject(JSPlatform, JVMPlatform)
.in(file("zio-json-macros"))
.settings(stdSettings("zio-json-macros"))
.settings(crossProjectSettings)
.settings(macroExpansionSettings)
.settings(
crossScalaVersions -= ScalaDotty,
scalacOptions -= "-Xfatal-warnings", // not quite ready.
libraryDependencies ++= Seq(
"org.scala-lang" % "scala-reflect" % scalaVersion.value % Provided,
"dev.zio" %%% "zio-test" % zioVersion % "test",
"dev.zio" %%% "zio-test-sbt" % zioVersion % "test"
),
testFrameworks += new TestFramework("zio.test.sbt.ZTestFramework")
)
lazy val zioJsonMacrosJVM = zioJsonMacros.jvm.dependsOn(zioJsonJVM)
lazy val zioJsonMacrosJS = zioJsonMacros.js
.settings(coverageEnabled := false)
.dependsOn(zioJsonJS)
lazy val zioJsonInteropHttp4s = project
.in(file("zio-json-interop-http4s"))
.settings(stdSettings("zio-json-interop-http4s"))
.settings(buildInfoSettings("zio.json.interop.http4s"))
.settings(
crossScalaVersions -= ScalaDotty,
libraryDependencies ++= Seq(
"org.http4s" %% "http4s-dsl" % "0.21.32",
"dev.zio" %% "zio" % zioVersion,
"org.typelevel" %% "cats-effect" % "2.5.4",
"dev.zio" %% "zio-interop-cats" % "2.5.1.0" % "test",
"dev.zio" %% "zio-test" % zioVersion % "test",
"dev.zio" %% "zio-test-sbt" % zioVersion % "test"
),
testFrameworks += new TestFramework("zio.test.sbt.ZTestFramework")
)
.dependsOn(zioJsonJVM)
.enablePlugins(BuildInfoPlugin)
lazy val zioJsonInteropRefined = crossProject(JSPlatform, JVMPlatform)
.in(file("zio-json-interop-refined"))
.jvmConfigure(_.dependsOn(zioJsonJVM))
.jsConfigure(_.dependsOn(zioJsonJS))
.settings(stdSettings("zio-json-interop-refined"))
.settings(buildInfoSettings("zio.json.interop.refined"))
.settings(
crossScalaVersions -= ScalaDotty,
libraryDependencies ++= Seq(
"eu.timepit" %%% "refined" % "0.9.28",
"dev.zio" %%% "zio-test" % zioVersion % "test",
"dev.zio" %%% "zio-test-sbt" % zioVersion % "test"
),
testFrameworks += new TestFramework("zio.test.sbt.ZTestFramework")
)
.enablePlugins(BuildInfoPlugin)
lazy val zioJsonInteropScalaz7x = crossProject(JSPlatform, JVMPlatform)
.in(file("zio-json-interop-scalaz7x"))
.jvmConfigure(_.dependsOn(zioJsonJVM))
.jsConfigure(_.dependsOn(zioJsonJS))
.settings(stdSettings("zio-json-interop-scalaz7x"))
.settings(buildInfoSettings("zio.json.interop.scalaz7x"))
.settings(
crossScalaVersions -= ScalaDotty,
libraryDependencies ++= Seq(
"org.scalaz" %%% "scalaz-core" % "7.3.6",
"dev.zio" %%% "zio-test" % zioVersion % "test",
"dev.zio" %%% "zio-test-sbt" % zioVersion % "test"
),
testFrameworks += new TestFramework("zio.test.sbt.ZTestFramework")
)
.enablePlugins(BuildInfoPlugin)
lazy val docs = project
.in(file("zio-json-docs"))
.dependsOn(
zioJsonJVM,
zioJsonYaml,
zioJsonMacrosJVM,
zioJsonInteropHttp4s,
zioJsonInteropRefined.jvm,
zioJsonInteropScalaz7x.jvm
)
.settings(
crossScalaVersions -= ScalaDotty,
publish / skip := true,
mdocVariables := Map(
"SNAPSHOT_VERSION" -> version.value,
"RELEASE_VERSION" -> previousStableVersion.value.getOrElse("can't find release"),
"ORG" -> organization.value,
"NAME" -> (zioJsonJVM / name).value,
"CROSS_VERSIONS" -> (zioJsonJVM / crossScalaVersions).value.mkString(", ")
),
moduleName := "zio-json-docs",
scalacOptions -= "-Yno-imports",
scalacOptions -= "-Xfatal-warnings",
libraryDependencies ++= Seq(
"dev.zio" %% "zio" % zioVersion
),
ScalaUnidoc / unidoc / unidocProjectFilter := inProjects(
zioJsonJVM,
zioJsonYaml,
zioJsonMacrosJVM,
zioJsonInteropHttp4s,
zioJsonInteropRefined.jvm,
zioJsonInteropScalaz7x.jvm
),
ScalaUnidoc / unidoc / target := (LocalRootProject / baseDirectory).value / "website" / "static" / "api",
cleanFiles += (ScalaUnidoc / unidoc / target).value,
docusaurusCreateSite := docusaurusCreateSite.dependsOn(Compile / unidoc).value,
docusaurusPublishGhpages := docusaurusPublishGhpages.dependsOn(Compile / unidoc).value
)
.enablePlugins(MdocPlugin, DocusaurusPlugin, ScalaUnidocPlugin)