forked from circe/circe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sbt
528 lines (467 loc) · 18.1 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
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
import ReleaseTransformations._
import microsites.ExtraMdFileConfig
import org.scalajs.sbtplugin.cross.{ CrossProject, CrossType }
import scala.xml.{ Elem, Node => XmlNode, NodeSeq => XmlNodeSeq }
import scala.xml.transform.{ RewriteRule, RuleTransformer }
organization in ThisBuild := "io.circe"
lazy val compilerOptions = Seq(
"-deprecation",
"-encoding", "UTF-8",
"-feature",
"-language:existentials",
"-language:higherKinds",
"-unchecked",
"-Yno-adapted-args",
"-Ywarn-dead-code",
"-Ywarn-numeric-widen",
"-Xfuture",
"-Yno-predef"
)
lazy val catsVersion = "1.0.0-MF"
lazy val jawnVersion = "0.11.0"
lazy val shapelessVersion = "2.3.2"
lazy val refinedVersion = "0.8.3"
lazy val monocleVersion = "1.4.0"
lazy val scalaTestVersion = "3.0.3"
lazy val scalaCheckVersion = "1.13.5"
lazy val disciplineVersion = "0.7.3"
lazy val previousCirceVersion = Some("0.8.0")
lazy val baseSettings = Seq(
scalacOptions ++= compilerOptions ++ (
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, p)) if p >= 11 => Seq("-Ywarn-unused-import")
case _ => Nil
}
),
scalacOptions in (Compile, console) ~= {
_.filterNot(Set("-Ywarn-unused-import", "-Yno-predef"))
},
scalacOptions in (Test, console) ~= {
_.filterNot(Set("-Ywarn-unused-import", "-Yno-predef"))
},
scalacOptions in Test ~= {
_.filterNot(Set("-Yno-predef"))
},
resolvers ++= Seq(
Resolver.sonatypeRepo("releases"),
Resolver.sonatypeRepo("snapshots")
),
coverageHighlighting := (
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 10)) => false
case _ => true
}
),
coverageScalacPluginVersion := "1.3.1",
(scalastyleSources in Compile) ++= (unmanagedSourceDirectories in Compile).value,
ivyConfigurations += config("compile-time").hide,
unmanagedClasspath in Compile ++= update.value.select(configurationFilter("compile-time")),
unmanagedClasspath in Test ++= update.value.select(configurationFilter("compile-time"))
)
lazy val allSettings = baseSettings ++ publishSettings
def circeProject(path: String)(project: Project) = {
val docName = path.split("-").mkString(" ")
project.settings(
description := s"circe $docName",
moduleName := s"circe-$path",
name := s"Circe $docName",
allSettings
)
}
def circeModule(path: String, mima: Option[String]): Project = {
val id = path.split("-").reduce(_ + _.capitalize)
Project(id, file(s"modules/$path"))
.configure(circeProject(path))
.settings(mimaPreviousArtifacts := mima.map("io.circe" %% moduleName.value % _).toSet)
}
def circeCrossModule(path: String, mima: Option[String], crossType: CrossType = CrossType.Full) = {
val id = path.split("-").reduce(_ + _.capitalize)
CrossProject(jvmId = id, jsId = id + "JS", file(s"modules/$path"), crossType)
.settings(allSettings)
.configureAll(circeProject(path))
.jvmSettings(
mimaPreviousArtifacts := mima.map("io.circe" %% moduleName.value % _).toSet
)
}
/**
* We omit all Scala.js projects from Unidoc generation, as well as
* circe-generic on 2.10, since Unidoc doesn't like its macros.
*/
def noDocProjects(sv: String): Seq[ProjectReference] = {
val unwanted = circeCrossModules.map(_._2) ++ circeUtilModules :+ tests
val scala210 = CrossVersion.partialVersion(sv) match {
case Some((2, 10)) => Seq(generic, literal)
case _ => Nil
}
(unwanted ++ jvm8Only(java8) ++ scala210).map(p => p: ProjectReference)
}
lazy val docSettings = allSettings ++ Seq(
micrositeName := "circe",
micrositeDescription := "A JSON library for Scala powered by Cats",
micrositeAuthor := "Travis Brown",
micrositeHighlightTheme := "atom-one-light",
micrositeHomepage := "https://circe.github.io/circe/",
micrositeBaseUrl := "circe",
micrositeDocumentationUrl := "api",
micrositeGithubOwner := "circe",
micrositeGithubRepo := "circe",
micrositeExtraMdFiles := Map(file("CONTRIBUTING.md") -> ExtraMdFileConfig("contributing.md", "docs")),
micrositePalette := Map(
"brand-primary" -> "#5B5988",
"brand-secondary" -> "#292E53",
"brand-tertiary" -> "#222749",
"gray-dark" -> "#49494B",
"gray" -> "#7B7B7E",
"gray-light" -> "#E5E5E6",
"gray-lighter" -> "#F4F3F4",
"white-color" -> "#FFFFFF"),
addMappingsToSiteDir(mappings in (ScalaUnidoc, packageDoc), micrositeDocumentationUrl),
ghpagesNoJekyll := false,
scalacOptions in (ScalaUnidoc, unidoc) ++= Seq(
"-groups",
"-implicits",
"-skip-packages", "scalaz",
"-doc-source-url", scmInfo.value.get.browseUrl + "/tree/master€{FILE_PATH}.scala",
"-sourcepath", baseDirectory.in(LocalRootProject).value.getAbsolutePath,
"-doc-root-content", (resourceDirectory.in(Compile).value / "rootdoc.txt").getAbsolutePath
),
scalacOptions ~= {
_.filterNot(Set("-Yno-predef"))
},
git.remoteRepo := "git@github.com:circe/circe.git",
unidocProjectFilter in (ScalaUnidoc, unidoc) :=
inAnyProject -- inProjects(noDocProjects(scalaVersion.value): _*),
includeFilter in makeSite := "*.html" | "*.css" | "*.png" | "*.jpg" | "*.gif" | "*.svg" | "*.js" | "*.swf" | "*.yml" | "*.md"
)
lazy val docs = project.dependsOn(core, genericExtras, parser, optics)
.settings(
moduleName := "circe-docs",
name := "Circe docs"
)
.settings(docSettings)
.settings(noPublishSettings)
.settings(
addCompilerPlugin("org.scalamacros" % "paradise" % "2.1.0" cross CrossVersion.patch)
)
.enablePlugins(GhpagesPlugin)
.enablePlugins(MicrositesPlugin)
.enablePlugins(ScalaUnidocPlugin)
lazy val circeCrossModules = Seq[(Project, Project)](
(numbersTesting, numbersTestingJS),
(numbers, numbersJS),
(core, coreJS),
(generic, genericJS),
(genericExtras, genericExtrasJS),
(shapes, shapesJS),
(literal, literalJS),
(optics, opticsJS),
(refined, refinedJS),
(parser, parserJS),
(scodec, scodecJS),
(java8, java8JS),
(testing, testingJS),
(tests, testsJS)
)
lazy val circeJsModules = Seq[Project](scalajs)
lazy val circeJvmModules = Seq[Project](jawn, streaming)
lazy val circeDocsModules = Seq[Project](docs)
lazy val circeUtilModules = Seq[Project](hygiene, benchmark)
def jvm8Only(projects: Project*): Set[Project] = sys.props("java.specification.version") match {
case "1.8" => Set.empty
case _ => Set(projects: _*)
}
lazy val jvmProjects: Seq[Project] =
(circeCrossModules.map(_._1) ++ circeJvmModules).filterNot(jvm8Only(java8))
lazy val jsProjects: Seq[Project] =
(circeCrossModules.map(_._2) ++ circeJsModules)
/**
* Aggregation should ensure that publish works as expected on the given
* JVM version. The `validate` command aliases will filter out projects
* not supported by the given JVM.
*/
lazy val aggregatedProjects: Seq[ProjectReference] =
(circeCrossModules.flatMap(cp => Seq(cp._1, cp._2)) ++
circeJsModules ++ circeJvmModules ++ circeDocsModules ++ circeUtilModules)
.filterNot(jvm8Only(java8)).map(p => p: ProjectReference)
def macroSettings(scaladocFor210: Boolean): Seq[Setting[_]] = Seq(
libraryDependencies ++= Seq(
scalaOrganization.value % "scala-compiler" % scalaVersion.value % Provided,
scalaOrganization.value % "scala-reflect" % scalaVersion.value % Provided,
"org.typelevel" %%% "macro-compat" % "1.1.1",
compilerPlugin("org.scalamacros" % "paradise" % "2.1.0" cross CrossVersion.patch)
),
libraryDependencies ++= {
CrossVersion.partialVersion(scalaVersion.value) match {
// if scala 2.11+ is used, quasiquotes are merged into scala-reflect.
case Some((2, scalaMajor)) if scalaMajor >= 11 => Nil
// in Scala 2.10, quasiquotes are provided by macro paradise.
case Some((2, 10)) => Seq("org.scalamacros" %% "quasiquotes" % "2.1.0" cross CrossVersion.binary)
}
},
sources in (Compile, doc) := {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 10)) if !scaladocFor210 => Nil
case _ => (sources in (Compile, doc)).value
}
}
)
lazy val circe = project.in(file("."))
.settings(allSettings)
.settings(noPublishSettings)
.settings(
addCompilerPlugin("org.scalamacros" % "paradise" % "2.1.0" cross CrossVersion.patch),
initialCommands in console :=
"""
|import io.circe._
|import io.circe.generic.auto._
|import io.circe.literal._
|import io.circe.parser._
|import io.circe.syntax._
""".stripMargin
)
.aggregate(aggregatedProjects: _*)
.dependsOn(core, genericExtras, literal, parser)
lazy val numbersTestingBase = circeCrossModule("numbers-testing", mima = previousCirceVersion, CrossType.Pure)
.settings(
scalacOptions ~= {
_.filterNot(Set("-Yno-predef"))
},
libraryDependencies += "org.scalacheck" %%% "scalacheck" % scalaCheckVersion,
coverageExcludedPackages := "io\\.circe\\.numbers\\.testing\\..*"
)
lazy val numbersTesting = numbersTestingBase.jvm
lazy val numbersTestingJS = numbersTestingBase.js
lazy val numbersBase = circeCrossModule("numbers", mima = previousCirceVersion)
.settings(
libraryDependencies ++= Seq(
"org.scalacheck" %%% "scalacheck" % scalaCheckVersion % Test,
"org.scalatest" %%% "scalatest" % scalaTestVersion % Test
)
).dependsOn(numbersTestingBase % Test)
lazy val numbers = numbersBase.jvm
lazy val numbersJS = numbersBase.js
lazy val coreBase = circeCrossModule("core", mima = previousCirceVersion)
.settings(
libraryDependencies += "org.typelevel" %%% "cats-core" % catsVersion,
sourceGenerators in Compile += (sourceManaged in Compile).map(Boilerplate.gen).taskValue
)
.dependsOn(numbersBase)
lazy val core = coreBase.jvm
lazy val coreJS = coreBase.js
lazy val genericBase = circeCrossModule("generic", mima = previousCirceVersion)
.settings(macroSettings(scaladocFor210 = false))
.settings(
libraryDependencies += "com.chuusai" %%% "shapeless" % shapelessVersion
)
.jsConfigure(_.settings(libraryDependencies += "org.spire-math" %% "jawn-parser" % jawnVersion % Test))
.dependsOn(coreBase, testsBase % Test, literalBase % Test)
lazy val generic = genericBase.jvm
lazy val genericJS = genericBase.js
lazy val genericExtrasBase = circeCrossModule("generic-extras", mima = previousCirceVersion, CrossType.Pure)
.settings(macroSettings(scaladocFor210 = false))
.jsConfigure(_.settings(libraryDependencies += "org.spire-math" %% "jawn-parser" % jawnVersion % Test))
.dependsOn(genericBase, testsBase % Test, literalBase % Test)
lazy val genericExtras = genericExtrasBase.jvm
lazy val genericExtrasJS = genericExtrasBase.js
lazy val shapesBase = circeCrossModule("shapes", mima = previousCirceVersion, CrossType.Pure)
.settings(macroSettings(scaladocFor210 = true))
.settings(
libraryDependencies += "com.chuusai" %%% "shapeless" % shapelessVersion
)
.jsConfigure(_.settings(libraryDependencies += "org.spire-math" %% "jawn-parser" % jawnVersion % Test))
.dependsOn(coreBase, testsBase % Test, literalBase % Test)
lazy val shapes = shapesBase.jvm
lazy val shapesJS = shapesBase.js
lazy val literalBase = circeCrossModule("literal", mima = previousCirceVersion, CrossType.Pure)
.settings(macroSettings(scaladocFor210 = false))
.settings(libraryDependencies += "com.chuusai" %%% "shapeless" % shapelessVersion % Test)
.jsConfigure(_.settings(libraryDependencies += "org.spire-math" %% "jawn-parser" % jawnVersion % Test))
.dependsOn(coreBase, parserBase % Test, testingBase % Test)
lazy val literal = literalBase.jvm
lazy val literalJS = literalBase.js
lazy val refinedBase = circeCrossModule("refined", mima = previousCirceVersion)
.settings(
libraryDependencies ++= Seq(
"eu.timepit" %%% "refined" % refinedVersion,
"eu.timepit" %%% "refined-scalacheck" % refinedVersion % Test
)
)
.dependsOn(coreBase, testsBase % Test)
lazy val refined = refinedBase.jvm
lazy val refinedJS = refinedBase.js
lazy val parserBase = circeCrossModule("parser", mima = previousCirceVersion)
.jvmConfigure(_.dependsOn(jawn))
.jsConfigure(_.dependsOn(scalajs))
.dependsOn(coreBase)
lazy val parser = parserBase.jvm
lazy val parserJS = parserBase.js
lazy val scalajs = circeModule("scalajs", mima = None)
.enablePlugins(ScalaJSPlugin)
.dependsOn(coreJS)
lazy val scodecBase = circeCrossModule("scodec", mima = previousCirceVersion)
.settings(
libraryDependencies += "org.scodec" %%% "scodec-bits" % "1.1.4"
)
.dependsOn(coreBase, testsBase % Test)
lazy val scodec = scodecBase.jvm
lazy val scodecJS = scodecBase.js
lazy val testingBase = circeCrossModule("testing", mima = previousCirceVersion)
.settings(
scalacOptions ~= {
_.filterNot(Set("-Yno-predef"))
},
libraryDependencies ++= Seq(
"org.scalacheck" %%% "scalacheck" % scalaCheckVersion % Test,
"org.scalatest" %%% "scalatest" % scalaTestVersion,
"org.typelevel" %%% "cats-laws" % catsVersion,
"org.typelevel" %%% "discipline" % disciplineVersion
)
)
.settings(
coverageExcludedPackages := "io\\.circe\\.testing\\..*"
)
.dependsOn(coreBase, numbersTestingBase)
lazy val testing = testingBase.jvm
lazy val testingJS = testingBase.js
lazy val testsBase = circeCrossModule("tests", mima = None)
.settings(noPublishSettings: _*)
.settings(
scalacOptions ~= {
_.filterNot(Set("-Yno-predef"))
},
libraryDependencies ++= Seq(
"com.chuusai" %%% "shapeless" % shapelessVersion,
"org.scalacheck" %%% "scalacheck" % scalaCheckVersion,
"org.scalatest" %%% "scalatest" % scalaTestVersion,
"org.typelevel" %%% "cats-laws" % catsVersion,
"org.typelevel" %%% "discipline" % disciplineVersion
),
sourceGenerators in Test += (sourceManaged in Test).map(Boilerplate.genTests).taskValue,
unmanagedResourceDirectories in Compile +=
file("modules/tests") / "shared" / "src" / "main" / "resources"
)
.settings(
coverageExcludedPackages := "io\\.circe\\.tests\\..*"
)
.jvmSettings(fork := true)
.dependsOn(coreBase, parserBase, testingBase)
lazy val tests = testsBase.jvm
lazy val testsJS = testsBase.js
lazy val hygiene = circeModule("hygiene", mima = None)
.settings(noPublishSettings)
.settings(
crossScalaVersions := crossScalaVersions.value.tail,
scalacOptions ++= Seq("-Yno-imports", "-Yno-predef")
)
.dependsOn(core, generic, jawn, literal)
lazy val jawn = circeModule("jawn", mima = previousCirceVersion)
.settings(
libraryDependencies += "org.spire-math" %% "jawn-parser" % jawnVersion
)
.dependsOn(core)
lazy val java8Base = circeCrossModule("java8", mima = previousCirceVersion, CrossType.Pure)
.dependsOn(coreBase, testsBase % Test)
.jsSettings(
libraryDependencies += "io.github.cquiroz" %%% "scala-java-time" % "2.0.0-M12"
)
lazy val java8 = java8Base.jvm
lazy val java8JS = java8Base.js
lazy val streaming = circeModule("streaming", mima = previousCirceVersion)
.settings(
libraryDependencies += "io.iteratee" %% "iteratee-core" % "0.13.0"
)
.dependsOn(core, jawn, tests % Test)
lazy val opticsBase = circeCrossModule("optics", mima = previousCirceVersion, CrossType.Pure)
.settings(
libraryDependencies ++= Seq(
"com.github.julien-truffaut" %%% "monocle-core" % monocleVersion,
"com.github.julien-truffaut" %%% "monocle-law" % monocleVersion % Test,
compilerPlugin("org.scalamacros" % "paradise" % "2.1.0" cross CrossVersion.patch)
)
)
.dependsOn(coreBase, genericBase % Test, testsBase % Test)
lazy val optics = opticsBase.jvm
lazy val opticsJS = opticsBase.js
lazy val benchmark = circeModule("benchmark", mima = None)
.settings(noPublishSettings)
.settings(
crossScalaVersions := crossScalaVersions.value.init,
scalacOptions ~= {
_.filterNot(Set("-Yno-predef"))
},
libraryDependencies ++= Seq(
"org.scalatest" %% "scalatest" % scalaTestVersion % Test,
compilerPlugin("org.scalamacros" % "paradise" % "2.1.0" cross CrossVersion.patch)
)
)
.enablePlugins(JmhPlugin)
.dependsOn(core, generic, jawn)
lazy val publishSettings = Seq(
releaseCrossBuild := true,
releasePublishArtifactsAction := PgpKeys.publishSigned.value,
homepage := Some(url("https://github.com/circe/circe")),
licenses := Seq("Apache 2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0")),
publishMavenStyle := true,
publishArtifact in Test := false,
pomIncludeRepository := { _ => false },
publishTo := {
val nexus = "https://oss.sonatype.org/"
if (isSnapshot.value)
Some("snapshots" at nexus + "content/repositories/snapshots")
else
Some("releases" at nexus + "service/local/staging/deploy/maven2")
},
autoAPIMappings := true,
apiURL := Some(url("https://circe.github.io/circe/api/")),
scmInfo := Some(
ScmInfo(
url("https://github.com/circe/circe"),
"scm:git:git@github.com:circe/circe.git"
)
),
developers := List(
Developer("travisbrown", "Travis Brown", "travisrobertbrown@gmail.com",
url("https://twitter.com/travisbrown"))
),
pomPostProcess := { (node: XmlNode) =>
new RuleTransformer(
new RewriteRule {
private def isTestScope(elem: Elem): Boolean =
elem.label == "dependency" && elem.child.exists(child => child.label == "scope" && child.text == "test")
override def transform(node: XmlNode): XmlNodeSeq = node match {
case elem: Elem if isTestScope(elem) => Nil
case _ => node
}
}
).transform(node).head
}
)
lazy val noPublishSettings = Seq(
publish := (),
publishLocal := (),
publishArtifact := false
)
credentials ++= (
for {
username <- Option(System.getenv().get("SONATYPE_USERNAME"))
password <- Option(System.getenv().get("SONATYPE_PASSWORD"))
} yield Credentials(
"Sonatype Nexus Repository Manager",
"oss.sonatype.org",
username,
password
)
).toSeq
val jvmTestProjects = jvmProjects.filterNot(Set(core, jawn, parser))
val jsTestProjects = jsProjects.filterNot(Set(core, parser, scalajs))
addCommandAlias("buildJVM", jvmProjects.map(";" + _.id + "/compile").mkString)
addCommandAlias(
"validateJVM",
";buildJVM" + jvmTestProjects.map(";" + _.id + "/test").mkString + ";scalastyle;unidoc"
)
addCommandAlias("buildJS", jsProjects.map(";" + _.id + "/compile").mkString)
addCommandAlias(
"validateJS",
";buildJS" + jsTestProjects.map(";" + _.id + "/test").mkString + ";scalastyle"
)
addCommandAlias("validate", ";validateJVM;validateJS")