-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.sbt
426 lines (400 loc) · 16.5 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
import com.jsuereth.sbtpgp.PgpKeys.publishSigned
import com.typesafe.tools.mima.core.{MissingClassProblem, MissingTypesProblem, Problem, ProblemFilters}
import commandmatrix.extra.*
// Used to configure the build so that it would format on compile during development but not on CI.
lazy val isCI = sys.env.get("CI").contains("true")
ThisBuild / scalafmtOnCompile := !isCI
lazy val ciRelease = taskKey[Unit](
"Publish artifacts to release or snapshot (skipping sonatypeBundleRelease which is unnecessary for snapshots)"
)
ciRelease := {
publishSigned.taskValue
Def.taskIf {
if (git.gitCurrentTags.value.nonEmpty) {
sonatypeBundleRelease.taskValue
}
}
}
// Versions:
val versions = new {
val scala212 = "2.12.20"
val scala213 = "2.13.15"
val scala3 = "3.3.4"
// Which versions should be cross-compiled for publishing
val scalas = List(scala212, scala213, scala3)
val platforms = List(VirtualAxis.jvm, VirtualAxis.js, VirtualAxis.native)
// Which version should be used in IntelliJ
val ideScala = scala3
val idePlatform = VirtualAxis.jvm
// Dependencies
val chimney = "1.4.0"
val enumeratum = "1.7.5"
val munit = "1.0.2"
}
// Common settings:
Global / excludeLintKeys += git.useGitDescribe
Global / excludeLintKeys += ideSkipProject
Global / excludeLintKeys += excludeDependencies
val only1VersionInIDE =
MatrixAction
.ForPlatform(versions.idePlatform)
.Configure(
_.settings(
ideSkipProject := (scalaVersion.value != versions.ideScala),
bspEnabled := (scalaVersion.value == versions.ideScala),
scalafmtOnCompile := !isCI
)
) +:
versions.platforms.filter(_ != versions.idePlatform).map { platform =>
MatrixAction
.ForPlatform(platform)
.Configure(_.settings(ideSkipProject := true, bspEnabled := false, scalafmtOnCompile := false))
}
val addScalaJVM2Dir =
MatrixAction
.ForPlatform(VirtualAxis.jvm)
.Configure(
_.settings(
Compile / unmanagedSourceDirectories ++= {
if (scalaVersion.value.startsWith("2.")) Seq(sourceDirectory.value.toPath.resolve("main/scalajvm-2").toFile)
else Seq()
},
Test / unmanagedSourceDirectories ++= {
if (scalaVersion.value.startsWith("2.")) Seq(sourceDirectory.value.toPath.resolve("test/scalajvm-2").toFile)
else Seq()
}
)
)
val addScala213plusDir =
MatrixAction
.ForScala(v => (v.value == versions.scala213) || v.isScala3)
.Configure(
_.settings(
Compile / unmanagedSourceDirectories += sourceDirectory.value.toPath.resolve("main/scala-2.13+").toFile,
Test / unmanagedSourceDirectories += sourceDirectory.value.toPath.resolve("test/scala-2.13+").toFile
)
)
val settings = Seq(
git.useGitDescribe := true,
git.uncommittedSignifier := None,
scalacOptions ++= {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((3, _)) =>
Seq(
// format: off
"-encoding", "UTF-8",
"-rewrite",
"-source", "3.3-migration",
// format: on
"-unchecked",
"-deprecation",
"-explain",
"-explain-types",
"-feature",
"-Wconf:msg=Unreachable case:s", // suppress fake (?) errors in internal.compiletime
// "-Wnonunit-statement",
// "-Wunused:imports", // import x.Underlying as X is marked as unused even though it is! probably one of https://github.com/scala/scala3/issues/: #18564, #19252, #19657, #19912
"-Wunused:privates",
"-Wunused:locals",
"-Wunused:explicits",
"-Wunused:implicits",
"-Wunused:params",
// "-Wvalue-discard",
"-Xfatal-warnings",
"-Xcheck-macros",
"-Ykind-projector:underscores"
)
case Some((2, 13)) =>
Seq(
// format: off
"-encoding", "UTF-8",
"-release", "8",
// format: on
"-unchecked",
"-deprecation",
"-explaintypes",
"-feature",
"-language:higherKinds",
"-Wconf:msg=discarding unmoored doc comment:s", // silence errors when scaladoc cannot comprehend nested vals
"-Wconf:msg=Could not find any member to link for:s", // since errors when scaladoc cannot link to stdlib types or nested types
"-Wconf:msg=Variable .+ undefined in comment for:s", // silence errors when there we're showing a buggy Expr in scaladoc comment
"-Wunused:patvars",
"-Xfatal-warnings",
"-Xlint:adapted-args",
"-Xlint:delayedinit-select",
"-Xlint:doc-detached",
"-Xlint:inaccessible",
"-Xlint:infer-any",
"-Xlint:nullary-unit",
"-Xlint:option-implicit",
"-Xlint:package-object-classes",
"-Xlint:poly-implicit-overload",
"-Xlint:private-shadow",
"-Xlint:stars-align",
"-Xlint:type-parameter-shadow",
"-Xsource:3",
"-Ywarn-dead-code",
"-Ywarn-numeric-widen",
"-Ywarn-unused:locals",
"-Ywarn-unused:imports",
"-Ywarn-macros:after",
"-Ytasty-reader"
)
case Some((2, 12)) =>
Seq(
// format: off
"-encoding", "UTF-8",
"-target:jvm-1.8",
// format: on
"-unchecked",
"-deprecation",
"-explaintypes",
"-feature",
"-language:higherKinds",
"-Wconf:cat=deprecation&origin=io.scalaland.chimney.*:s", // we want to be able to deprecate APIs and test them while they're deprecated
"-Wconf:msg=The outer reference in this type test cannot be checked at run time:s", // suppress fake(?) errors in internal.compiletime (adding origin breaks this suppression)
"-Wconf:src=io/scalaland/chimney/cats/package.scala:s", // silence package object inheritance deprecation
"-Wconf:msg=discarding unmoored doc comment:s", // silence errors when scaladoc cannot comprehend nested vals
"-Wconf:msg=Could not find any member to link for:s", // since errors when scaladoc cannot link to stdlib types or nested types
"-Wconf:msg=Variable .+ undefined in comment for:s", // silence errors when there we're showing a buggy Expr in scaladoc comment
"-Xexperimental",
"-Xfatal-warnings",
"-Xfuture",
"-Xlint:adapted-args",
"-Xlint:by-name-right-associative",
"-Xlint:delayedinit-select",
"-Xlint:doc-detached",
"-Xlint:inaccessible",
"-Xlint:infer-any",
"-Xlint:nullary-override",
"-Xlint:nullary-unit",
"-Xlint:option-implicit",
"-Xlint:package-object-classes",
"-Xlint:poly-implicit-overload",
"-Xlint:private-shadow",
"-Xlint:stars-align",
"-Xlint:type-parameter-shadow",
"-Xlint:unsound-match",
"-Xsource:3",
"-Yno-adapted-args",
"-Ywarn-dead-code",
"-Ywarn-inaccessible",
"-Ywarn-infer-any",
"-Ywarn-numeric-widen",
"-Ywarn-unused:locals",
"-Ywarn-unused:imports",
"-Ywarn-macros:after",
"-Ywarn-nullary-override",
"-Ywarn-nullary-unit"
)
case _ => Seq.empty
}
},
Compile / doc / scalacOptions ++= {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((3, _)) =>
Seq("-Ygenerate-inkuire") // type-based search for Scala 3, this option cannot go into compile
case _ => Seq.empty
}
},
Compile / console / scalacOptions --= Seq("-Ywarn-unused:imports", "-Xfatal-warnings"),
Test / compile / scalacOptions --= {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 12)) => Seq("-Ywarn-unused:locals") // Scala 2.12 ignores @unused warns
case _ => Seq.empty
}
} /*,
Compile / compile / wartremoverWarnings ++= Warts.allBut(
Wart.Any,
Wart.AsInstanceOf,
Wart.DefaultArguments,
Wart.ExplicitImplicitTypes,
Wart.ImplicitConversion,
Wart.ImplicitParameter,
Wart.Overloading,
Wart.PublicInference,
Wart.NonUnitStatements,
Wart.Nothing,
Wart.ToString
)*/
)
val versionSchemeSettings = Seq(versionScheme := Some("early-semver"))
val publishSettings = Seq(
organization := "io.scalaland",
homepage := Some(url("https://scalaland.io/enumz")),
organizationHomepage := Some(url("https://scalaland.io")),
licenses := Seq("Apache-2.0" -> url("https://www.apache.org/licenses/LICENSE-2.0")),
scmInfo := Some(
ScmInfo(url("https://github.com/scalalandio/enumz/"), "scm:git:[email protected]:scalalandio/enumz.git")
),
startYear := Some(2017),
developers := List(
Developer("MateuszKubuszok", "Mateusz Kubuszok", "", url("https://github.com/MateuszKubuszok"))
),
pomExtra := (
<issueManagement>
<system>GitHub issues</system>
<url>https://github.com/scalalandio/enumz/issues</url>
</issueManagement>
),
publishTo := sonatypePublishToBundle.value,
publishMavenStyle := true,
Test / publishArtifact := false,
pomIncludeRepository := { _ =>
false
},
// Sonatype ignores isSnapshot setting and only looks at -SNAPSHOT suffix in version:
// https://central.sonatype.org/publish/publish-maven/#performing-a-snapshot-deployment
// meanwhile sbt-git used to set up SNAPSHOT if there were uncommitted changes:
// https://github.com/sbt/sbt-git/issues/164
// (now this suffix is empty by default) so we need to fix it manually.
git.gitUncommittedChanges := git.gitCurrentTags.value.isEmpty,
git.uncommittedSignifier := Some("SNAPSHOT")
)
val mimaSettings = Seq(
mimaPreviousArtifacts := {
val previousVersions = moduleName.value match {
case "enumz" => Set("1.0.0", "1.1.0").filterNot(_ => scalaVersion.value == versions.scala3)
case "enumz-chimney" => Set("1.1.0")
case _ => Set()
}
previousVersions.map(organization.value %% moduleName.value % _)
},
mimaFailOnNoPrevious := true
)
val noPublishSettings =
Seq(publish / skip := true, publishArtifact := false)
val ciCommand = (platform: String, scalaSuffix: String) => {
val isJVM = platform == "JVM"
val clean = Vector("clean")
def withCoverage(tasks: String*): Vector[String] =
"coverage" +: tasks.toVector :+ "coverageAggregate" :+ "coverageOff"
val projects = Vector("enumz", "enumzChimney")
.map(name => s"$name${if (isJVM) "" else platform}$scalaSuffix")
def tasksOf(name: String): Vector[String] = projects.map(project => s"$project/$name")
val tasks = if (isJVM) {
clean ++
withCoverage((tasksOf("compile") ++ tasksOf("test") ++ tasksOf("coverageReport")).toSeq *) ++
tasksOf("mimaReportBinaryIssues")
} else {
clean ++ tasksOf("test")
}
tasks.mkString(" ; ")
}
val publishLocalForTests = {
for {
module <- Vector("enumz")
moduleVersion <- Vector(module, module + "3")
} yield moduleVersion + "/publishLocal"
}.mkString(" ; ")
val releaseCommand = (tag: Seq[String]) =>
if (tag.nonEmpty) "publishSigned ; sonatypeBundleRelease" else "publishSigned"
lazy val root = project
.in(file("."))
.enablePlugins(GitVersioning, GitBranchPrompt)
.settings(
moduleName := "enumz-build",
name := "enumz-build",
description := "Build setup for Enumz modules",
logo :=
s"""Enumz ${(version).value} build for (${versions.scala212}, ${versions.scala213}, ${versions.scala3}) x (Scala JVM, Scala.js $scalaJSVersion, Scala Native $nativeVersion)
|
|This build uses sbt-projectmatrix with sbt-commandmatrix helper:
| - Scala JVM adds no suffix to a project name seen in build.sbt
| - Scala.js adds the "JS" suffix to a project name seen in build.sbt
| - Scala Native adds the "Native" suffix to a project name seen in build.sbt
| - Scala 2.12 adds the suffix "2_12" to a project name seen in build.sbt
| - Scala 2.13 adds no suffix to a project name seen in build.sbt
| - Scala 3 adds the suffix "3" to a project name seen in build.sbt
|
|When working with IntelliJ or Scala Metals, edit "val ideScala = ..." and "val idePlatform = ..." within "val versions" in build.sbt to control which Scala version you're currently working with.
|
|If you need to test library locally in a different project, use publish-local-for-tests or manually publishLocal:
| - enumz (obligatory)
|for the right Scala version and platform (see projects task).
|""".stripMargin,
usefulTasks := Seq(
sbtwelcome.UsefulTask("projects", "List all projects generated by the build matrix").noAlias,
sbtwelcome
.UsefulTask(
"test",
"Compile and test all projects in all Scala versions and platforms (beware! it uses a lot of memory and might OOM!)"
)
.noAlias,
sbtwelcome.UsefulTask("enumz3/console", "Drop into REPL with Enumz imported (3)").noAlias,
sbtwelcome.UsefulTask("enumz/console", "Drop into REPL with Enumz imported (2.13)").noAlias,
sbtwelcome
.UsefulTask(releaseCommand(git.gitCurrentTags.value), "Publish everything to release or snapshot repository")
.alias("ci-release"),
sbtwelcome.UsefulTask(ciCommand("JVM", "3"), "CI pipeline for Scala 3 on JVM").alias("ci-jvm-3"),
sbtwelcome.UsefulTask(ciCommand("JVM", ""), "CI pipeline for Scala 2.13 on JVM").alias("ci-jvm-2_13"),
sbtwelcome.UsefulTask(ciCommand("JVM", "2_12"), "CI pipeline for Scala 2.12 on JVM").alias("ci-jvm-2_12"),
sbtwelcome.UsefulTask(ciCommand("JS", "3"), "CI pipeline for Scala 3 on Scala JS").alias("ci-js-3"),
sbtwelcome.UsefulTask(ciCommand("JS", ""), "CI pipeline for Scala 2.13 on Scala JS").alias("ci-js-2_13"),
sbtwelcome.UsefulTask(ciCommand("JS", "2_12"), "CI pipeline for Scala 2.12 on Scala JS").alias("ci-js-2_12"),
sbtwelcome.UsefulTask(ciCommand("Native", "3"), "CI pipeline for Scala 3 on Scala Native").alias("ci-native-3"),
sbtwelcome
.UsefulTask(ciCommand("Native", ""), "CI pipeline for Scala 2.13 on Scala Native")
.alias("ci-native-2_13"),
sbtwelcome
.UsefulTask(ciCommand("Native", "2_12"), "CI pipeline for Scala 2.12 on Scala Native")
.alias("ci-native-2_12"),
sbtwelcome
.UsefulTask(
publishLocalForTests,
"Publishes all Scala 2.13 and Scala 3 JVM artifacts to test snippets in documentation"
)
.alias("publish-local-for-tests")
)
)
.settings(settings)
.settings(versionSchemeSettings)
.settings(publishSettings)
.settings(noPublishSettings)
.aggregate(enumz.projectRefs *)
.aggregate(enumzChimney.projectRefs *)
lazy val enumz = projectMatrix
.in(file("enumz"))
.someVariations(versions.scalas, versions.platforms)((addScalaJVM2Dir +: addScala213plusDir +: only1VersionInIDE) *)
.enablePlugins(GitVersioning, GitBranchPrompt)
.disablePlugins(WelcomePlugin)
.settings(
moduleName := "enumz",
name := "enumz",
description := "Common type class interface for various enums implementations"
)
.settings(settings *)
.settings(versionSchemeSettings *)
.settings(publishSettings *)
.settings(mimaSettings *)
.settings(
libraryDependencies += "com.beachape" %%% "enumeratum" % versions.enumeratum,
libraryDependencies += "org.scalameta" %%% "munit" % versions.munit % Test,
mimaBinaryIssueFilters := Seq(
// Users shouldn't rely on how we're handling implicit priorities (now we made them package private)
ProblemFilters.exclude[MissingClassProblem]("io.scalaland.enumz.Implicits"),
ProblemFilters.exclude[MissingClassProblem]("io.scalaland.enumz.LowPriorityImplicits"),
ProblemFilters.exclude[MissingTypesProblem]("io.scalaland.enumz.Enum$"),
// Changes to macros should not cause any problems
ProblemFilters.exclude[Problem]("io.scalaland.enumz.internal.*")
)
)
lazy val enumzChimney = projectMatrix
.in(file("enumz-chimney"))
.someVariations(versions.scalas, versions.platforms)((only1VersionInIDE) *)
.enablePlugins(GitVersioning, GitBranchPrompt)
.disablePlugins(WelcomePlugin)
.settings(
moduleName := "enumz-chimney",
name := "enumz-chimney",
description := "Chimney integration for runtime enum conversions using Enumz"
)
.settings(settings *)
.settings(versionSchemeSettings *)
.settings(publishSettings *)
.settings(mimaSettings *) // not yet released
.settings(
libraryDependencies += "io.scalaland" %%% "chimney" % versions.chimney,
libraryDependencies += "org.scalameta" %%% "munit" % versions.munit % Test
)
.dependsOn(enumz)