forked from circe/circe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sbt
488 lines (445 loc) · 17 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
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
import sbtcrossproject.{ CrossProject, CrossType }
val Scala212V: String = "2.12.19"
val Scala213V: String = "2.13.14"
val Scala3V: String = "3.3.3"
ThisBuild / startYear := Some(2024)
ThisBuild / tlBaseVersion := "0.14"
ThisBuild / tlCiReleaseBranches := Seq() // set to `series/0.14.x` once we get the automated publishing process up and running
ThisBuild / tlCiReleaseTags := true
ThisBuild / tlFatalWarnings := false // we currently have a lot of warnings that will need to be fixed
ThisBuild / organization := "io.circe"
ThisBuild / crossScalaVersions := List(Scala3V, Scala212V, Scala213V)
ThisBuild / scalaVersion := Scala213V
ThisBuild / githubWorkflowJavaVersions := Seq("8", "11", "17").map(JavaSpec.temurin)
ThisBuild / tlCiScalafixCheck := false // TODO: Address these in a follow up PR
ThisBuild / scalafixScalaBinaryVersion := CrossVersion.binaryScalaVersion(scalaVersion.value)
ThisBuild / scalafixAll / skip := tlIsScala3.value
ThisBuild / ScalafixConfig / skip := tlIsScala3.value
ThisBuild / circeRootOfCodeCoverage := Some("rootJVM")
val catsVersion = "2.10.0"
val jawnVersion = "1.5.1"
val shapelessVersion = "2.3.11"
val refinedVersion = "0.9.29"
val refinedNativeVersion = "0.11.1"
val paradiseVersion = "2.1.1"
val scalaCheckVersion = "1.17.1"
val munitVersion = "1.0.0-M11"
val disciplineVersion = "1.6.0"
val disciplineScalaTestVersion = "2.2.0"
val disciplineMunitVersion = "2.0.0-M3"
val scalaJavaTimeVersion = "2.5.0"
/**
* Some terrible hacks to work around Cats's decision to have builds for
* different Scala versions depend on different versions of Discipline, etc.
*/
def priorTo2_13(scalaVersion: String): Boolean =
CrossVersion.partialVersion(scalaVersion) match {
case Some((2, minor)) if minor < 13 => true
case _ => false
}
val scalaFiddleCirceVersion = "0.9.1"
lazy val allSettings = Seq()
/**
* Replace '/' with '-' in a path which represents a module name.
*
* The circe module's path is used in most cases to derive the module
* name. For some modules, this path includes sub-directories, e.g. scalafix
* internal rules. When this is the case, since the path is represented as a
* simple String, the '/' character can cause problems as the module name is
* used inside SBT and Coursier for Maven style artifact operations and '/'
* is not a valid character in a module name.
*/
def normalizeModuleNameFromPath(path: String): String =
path.replaceAll("/", "-")
def circeProject(path: String)(project: Project) = {
val docName = path.split("[-/]").mkString(" ")
project.settings(
description := s"circe $docName",
moduleName := s"circe-${normalizeModuleNameFromPath(path)}",
name := s"Circe $docName",
allSettings
)
}
/**
* This is here so we can use this with our internal Scalafix rules, without
* creating a cyclic dependency. So the scalafix modules will use this and
* the other modules will use either `circeModule` or `circeCrossModule`.
*/
def baseModule(path: String, additionalDeps: List[ClasspathDep[ProjectReference]] = Nil): Project = {
val id = path.split("[-/]").reduce(_ + _.capitalize)
Project(id, file(s"modules/$path")).configure(circeProject(path)).configure(_.dependsOn(additionalDeps: _*))
}
def circeModule(path: String): Project = baseModule(path, List(scalafixInternalRules % ScalafixConfig))
def circeCrossModule(path: String, crossType: CrossType = CrossType.Full) = {
val id = path.split("[-/]").reduce(_ + _.capitalize)
CrossProject(id, file(s"modules/$path"))(JVMPlatform, JSPlatform, NativePlatform)
.crossType(crossType)
.settings(allSettings)
.configure(circeProject(path))
.jsSettings(
coverageEnabled := false
)
.configure(_.dependsOn(scalafixInternalRules % ScalafixConfig))
.nativeSettings(
coverageEnabled := false,
tlVersionIntroduced := List("2.12", "2.13", "3").map(_ -> "0.14.3").toMap
)
}
lazy val docs = project
.in(file("site"))
.dependsOn(core.jvm, parser.jvm, shapes.jvm, testing.jvm)
.settings(
moduleName := "circe-docs",
name := "Circe docs",
libraryDependencies ++= Seq(
"io.circe" %% "circe-generic-extras" % "0.14.3",
"io.circe" %% "circe-optics" % "0.15.0"
),
tlSitePublishBranch := Some("series/0.14.x")
)
.enablePlugins(CirceOrgSitePlugin)
.settings(macroSettings)
lazy val macroSettings: Seq[Setting[_]] = Seq(
libraryDependencies ++= (if (tlIsScala3.value) Nil
else
Seq(
scalaOrganization.value % "scala-compiler" % scalaVersion.value % Provided,
scalaOrganization.value % "scala-reflect" % scalaVersion.value % Provided
) ++ (
if (scalaBinaryVersion.value == "2.12") {
Seq(
compilerPlugin(
("org.scalamacros" % "paradise" % paradiseVersion).cross(CrossVersion.patch)
)
)
} else Nil
)),
scalacOptions ++= (
if (Set("2.12", "3").contains(scalaBinaryVersion.value)) Nil else Seq("-Ymacro-annotations")
),
scalacOptions -= "-source:3.0-migration"
)
lazy val root = tlCrossRootProject
.settings(
console / initialCommands :=
"""
|import io.circe._
|import io.circe.generic.auto._
|import io.circe.literal._
|import io.circe.parser._
|import io.circe.syntax._
""".stripMargin
)
.aggregate(
benchmark,
core,
extras,
generic,
hygiene,
jawn,
literal,
numbers,
numbersTesting,
parser,
pointer,
pointerLiteral,
refined,
scalafixInternalInput,
scalafixInternalOutput,
scalafixInternalRules,
scalafixInternalTests,
scalajs,
scalajsJavaTimeTest,
scodec,
shapes,
testing,
tests
)
.disablePlugins(ScalafixPlugin)
lazy val scalafixInternalRules =
baseModule("scalafix/internal/rules")
.settings(
skip := tlIsScala3.value,
update / skip := false,
libraryDependencies ++= List(
"ch.epfl.scala" %% "scalafix-core" % _root_.scalafix.sbt.BuildInfo.scalafixVersion
).filterNot(_ => tlIsScala3.value)
)
.enablePlugins(NoPublishPlugin)
.disablePlugins(ScalafixPlugin)
lazy val scalafixInternalInput =
baseModule("scalafix/internal/input")
.settings(
skip := tlIsScala3.value,
update / skip := false
)
.disablePlugins(ScalafixPlugin)
.enablePlugins(NoPublishPlugin)
lazy val scalafixInternalOutput =
baseModule("scalafix/internal/output")
.settings(
skip := tlIsScala3.value,
update / skip := false
)
.disablePlugins(ScalafixPlugin)
.enablePlugins(NoPublishPlugin)
lazy val scalafixInternalTests =
baseModule("scalafix/internal/tests")
.enablePlugins(NoPublishPlugin, ScalafixTestkitPlugin)
.settings(
libraryDependencies := {
if (tlIsScala3.value)
libraryDependencies.value.filterNot(_.name == "scalafix-testkit")
else
libraryDependencies.value
},
scalafixTestkitOutputSourceDirectories :=
(scalafixInternalOutput / Compile / sourceDirectories).value,
scalafixTestkitInputSourceDirectories :=
(scalafixInternalInput / Compile / sourceDirectories).value,
scalafixTestkitInputClasspath :=
(scalafixInternalInput / Compile / fullClasspath).value,
scalafixTestkitInputScalacOptions :=
(scalafixInternalInput / Compile / scalacOptions).value,
scalafixTestkitInputScalaVersion :=
(scalafixInternalInput / Compile / scalaVersion).value,
libraryDependencies ++= Seq(
("ch.epfl.scala" %% "scalafix-testkit" % _root_.scalafix.sbt.BuildInfo.scalafixVersion % Test)
.cross(CrossVersion.full)
).filter(_ => !tlIsScala3.value),
Compile / compile :=
(Compile / compile).dependsOn(scalafixInternalInput / Compile / compile).value
)
.disablePlugins(ScalafixPlugin)
.dependsOn(scalafixInternalInput, scalafixInternalOutput, scalafixInternalRules)
lazy val numbersTesting =
circeCrossModule("numbers-testing", CrossType.Pure).settings(
libraryDependencies += "org.scalacheck" %%% "scalacheck" % scalaCheckVersion,
coverageExcludedPackages := "io\\.circe\\.numbers\\.testing\\..*"
)
lazy val numbers = circeCrossModule("numbers")
.settings(
libraryDependencies ++= Seq(
"org.scalameta" %%% "munit" % munitVersion % Test,
"org.typelevel" %%% "discipline-munit" % disciplineMunitVersion % Test
)
)
.dependsOn(numbersTesting % Test)
lazy val core = circeCrossModule("core")
.settings(
libraryDependencies += "org.typelevel" %%% "cats-core" % catsVersion,
Compile / sourceGenerators += Def.task {
val managedSource = (Compile / sourceManaged).value
val currentScalaVersion = (Compile / scalaBinaryVersion).value
Boilerplate.gen(managedSource, currentScalaVersion)
},
scalacOptions ~= (_.filterNot(Set("-source:3.0-migration")))
)
.dependsOn(numbers)
lazy val generic = circeCrossModule("generic")
.settings(macroSettings)
.settings(
libraryDependencies ++= (if (tlIsScala3.value) Nil
else Seq("com.chuusai" %%% "shapeless" % shapelessVersion))
)
.jsSettings(
libraryDependencies ++= Seq(
"org.typelevel" %% "jawn-parser" % jawnVersion % Test,
"io.github.cquiroz" %%% "scala-java-time" % scalaJavaTimeVersion % Test
)
)
.dependsOn(core, tests % Test)
lazy val genericSimple = circeCrossModule("generic-simple", CrossType.Pure)
.settings(macroSettings)
.settings(
crossScalaVersions := (ThisBuild / crossScalaVersions).value.filter(_.startsWith("2.13")),
libraryDependencies += "com.chuusai" %%% "shapeless" % shapelessVersion,
Test / classLoaderLayeringStrategy := ClassLoaderLayeringStrategy.AllLibraryJars
)
.platformsSettings(JSPlatform, NativePlatform)(
libraryDependencies ++= Seq(
"org.typelevel" %% "jawn-parser" % jawnVersion % Test,
"io.github.cquiroz" %%% "scala-java-time" % scalaJavaTimeVersion % Test
)
)
.dependsOn(core, tests % Test, literal % Test)
lazy val shapes = circeCrossModule("shapes", CrossType.Pure)
.settings(macroSettings)
.settings(
publish / skip := tlIsScala3.value,
publishArtifact := !tlIsScala3.value,
libraryDependencies += ("com.chuusai" %%% "shapeless" % shapelessVersion).cross(CrossVersion.for3Use2_13)
)
.platformsSettings(JSPlatform, NativePlatform)(
libraryDependencies ++= Seq(
"org.typelevel" %% "jawn-parser" % jawnVersion % Test,
"io.github.cquiroz" %%% "scala-java-time" % scalaJavaTimeVersion % Test
)
)
.dependsOn(core, tests % Test, literal % Test)
lazy val literal = circeCrossModule("literal", CrossType.Pure)
.settings(macroSettings)
.settings(
tlVersionIntroduced += "3" -> "0.14.2",
libraryDependencies ++= Seq(
"org.scalacheck" %%% "scalacheck" % scalaCheckVersion % Test,
"org.scalameta" %%% "munit" % munitVersion % Test,
"org.scalameta" %%% "munit-scalacheck" % munitVersion % Test
) ++ (if (tlIsScala3.value) Seq("org.typelevel" %%% "jawn-parser" % jawnVersion % Provided)
else Seq("com.chuusai" %%% "shapeless" % shapelessVersion))
)
.platformsSettings(JSPlatform, NativePlatform)(
libraryDependencies ++= Seq(
"io.github.cquiroz" %%% "scala-java-time" % scalaJavaTimeVersion % Test,
"org.typelevel" %%% "jawn-parser" % jawnVersion % Provided
)
)
.nativeSettings(
tlVersionIntroduced := List("2.12", "2.13", "3").map(_ -> "0.14.3").toMap
)
.dependsOn(core, parser % Test, testing % Test)
lazy val refined = circeCrossModule("refined")
.settings(
tlVersionIntroduced += "3" -> "0.14.3",
libraryDependencies ++= {
val refinedV =
if (crossProjectPlatform.value == NativePlatform) refinedNativeVersion
else refinedVersion
Seq(
"eu.timepit" %%% "refined" % refinedV,
"eu.timepit" %%% "refined-scalacheck" % refinedV % Test
)
},
dependencyOverrides ++= Seq(
"org.scala-lang.modules" %% "scala-xml" % "2.1.0"
),
Test / classLoaderLayeringStrategy := ClassLoaderLayeringStrategy.AllLibraryJars
)
.platformsSettings(JSPlatform, NativePlatform)(
libraryDependencies += "io.github.cquiroz" %%% "scala-java-time" % scalaJavaTimeVersion % Test
)
.dependsOn(core, tests % Test)
lazy val parser =
circeCrossModule("parser")
.jvmConfigure(_.dependsOn(jawn.jvm))
.jsConfigure(_.dependsOn(scalajs))
.nativeConfigure(_.dependsOn(jawn.native))
.dependsOn(core)
lazy val scalajs =
circeModule("scalajs").enablePlugins(ScalaJSPlugin).dependsOn(core.js)
lazy val scalajsJavaTimeTest = circeModule("scalajs-java-time-test")
.enablePlugins(ScalaJSPlugin)
.enablePlugins(NoPublishPlugin)
.settings(
libraryDependencies ++= Seq(
"org.scalameta" %%% "munit" % munitVersion % Test
)
)
.dependsOn(core.js)
lazy val scodec = circeCrossModule("scodec")
.settings(
libraryDependencies += "org.scodec" %%% "scodec-bits" % "1.1.38"
)
.platformsSettings(JSPlatform, NativePlatform)(
libraryDependencies += "io.github.cquiroz" %%% "scala-java-time" % scalaJavaTimeVersion % Test
)
.dependsOn(core, tests % Test)
lazy val testing = circeCrossModule("testing")
.settings(
scalacOptions ~= {
_.filterNot(Set("-Yno-predef"))
},
libraryDependencies ++= Seq(
"org.scalacheck" %%% "scalacheck" % scalaCheckVersion,
"org.typelevel" %%% "cats-laws" % catsVersion,
"org.typelevel" %%% "discipline-core" % disciplineVersion
)
)
.settings(
coverageExcludedPackages := "io\\.circe\\.testing\\..*"
)
.dependsOn(core, numbersTesting)
lazy val tests = circeCrossModule("tests")
.enablePlugins(NoPublishPlugin)
.settings(
scalacOptions ~= {
_.filterNot(Set("-Yno-predef", "-source:3.0-migration"))
},
Test / scalacOptions += "-language:implicitConversions",
libraryDependencies ++= Seq(
("com.chuusai" %%% "shapeless" % shapelessVersion).cross(CrossVersion.for3Use2_13),
"org.scalameta" %%% "munit" % munitVersion,
"org.typelevel" %%% "discipline-scalatest" % disciplineScalaTestVersion,
"org.typelevel" %%% "discipline-munit" % disciplineMunitVersion
),
Test / sourceGenerators += (Test / sourceManaged).map(Boilerplate.genTests).taskValue
)
.settings(
coverageExcludedPackages := "io\\.circe\\.tests\\..*"
)
.jvmSettings(
fork := true
)
.platformsSettings(JSPlatform, NativePlatform)(
libraryDependencies += "io.github.cquiroz" %%% "scala-java-time" % scalaJavaTimeVersion % Test
)
.nativeSettings(
nativeConfig ~= { _.withEmbedResources(true) }
)
.dependsOn(core, parser, testing, jawn)
lazy val hygiene = circeCrossModule("hygiene")
.enablePlugins(NoPublishPlugin)
.settings(
scalacOptions ++= Seq("-Yno-imports", "-Yno-predef")
)
.dependsOn(core, generic, literal, jawn)
lazy val jawn = circeCrossModule("jawn", CrossType.Full)
.settings(
libraryDependencies ++= Seq(
"org.typelevel" %%% "jawn-parser" % jawnVersion,
"org.scalameta" %%% "munit" % munitVersion % Test,
"org.typelevel" %%% "discipline-munit" % disciplineMunitVersion % Test
)
)
.jsSettings(
tlVersionIntroduced := List("2.12", "2.13", "3").map(_ -> "0.14.2").toMap
)
.dependsOn(core)
lazy val pointer =
circeCrossModule("pointer", CrossType.Pure)
.settings(
libraryDependencies ++= Seq(
"org.scalameta" %%% "munit" % munitVersion % Test,
"org.typelevel" %%% "discipline-munit" % disciplineMunitVersion % Test
)
)
.dependsOn(core, parser % Test)
lazy val pointerLiteral = circeCrossModule("pointer-literal", CrossType.Pure)
.settings(macroSettings)
.settings(
tlVersionIntroduced += "3" -> "0.14.2",
libraryDependencies ++= Seq(
"org.scalameta" %%% "munit" % munitVersion % Test,
"org.scalameta" %%% "munit-scalacheck" % munitVersion % Test
)
)
.nativeSettings(
tlVersionIntroduced := List("2.12", "2.13", "3").map(_ -> "0.14.3").toMap
)
.dependsOn(core, pointer % "compile;test->test")
lazy val extras = circeCrossModule("extras").enablePlugins(NoPublishPlugin).dependsOn(core, tests % Test)
lazy val benchmark = circeModule("benchmark")
.settings(
libraryDependencies ++= Seq(
"org.scalameta" %% "munit" % munitVersion % Test
) ++ { if (tlIsScala3.value) Nil else List("io.circe" %% "circe-optics" % "0.14.1") }
)
.enablePlugins(JmhPlugin, NoPublishPlugin)
.dependsOn(core.jvm, generic.jvm, jawn.jvm, pointer.jvm)
ThisBuild / homepage := Some(url("https://github.com/circe/circe"))
ThisBuild / licenses := Seq(License.Apache2)
ThisBuild / developers := List(
Developer("travisbrown", "Travis Brown", "[email protected]", url("https://twitter.com/travisbrown")),
Developer("zmccoy", "Zach McCoy", "[email protected]", url("https://twitter.com/zachamccoy")),
Developer("zarthross", "Darren Gibson", "[email protected]", url("https://twitter.com/zarthross"))
)