-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sbt
349 lines (326 loc) · 12.7 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
import com.jsuereth.sbtpgp.PgpKeys.publishSigned
import com.typesafe.tools.mima.core.{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.19"
val scala213 = "2.13.14"
val scala3 = "3.3.3"
// Which versions should be cross-compiled for publishing
val scalas = List(scala3)
val platforms = List(VirtualAxis.jvm, VirtualAxis.js, VirtualAxis.native)
// Which version should be used in IntelliJ
val ideScala = scala3
val idePlatform = VirtualAxis.jvm
}
// 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 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=object ImplicitConversions in package convert is deprecated:s", // 2.12 bincompat
// "-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=object ImplicitConversions in package convert is deprecated:s", // 2.12 bincompat
"-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",
"-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
}
}
)
val versionSchemeSettings = Seq(versionScheme := Some("early-semver"))
val publishSettings = Seq(
organization := "io.scalaland",
homepage := Some(url("https://scalaland.io/opinionated")),
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/opinionated/"), "scm:git:[email protected]:scalalandio/opinionated.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/opinionated/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 _ => Set()
}
previousVersions.map(organization.value %% moduleName.value % _)
},
mimaFailOnNoPrevious := false // before the first release
)
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("opinionated")
.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("opinionated", "opinionated-cats-effect", "opinionated-monix")
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 := "opinionated-build",
name := "opinionated-build",
description := "Build setup for MDC4s modules",
logo :=
s"""MDC4s ${(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:
| - opinionated-typelevel (optional)
| - opinionated-monix (optional)
|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(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(
(opinionatedTypelevel.projectRefs) *
)
lazy val opinionatedTypelevel = projectMatrix
.in(file("modules/opinionated-typelevel"))
.someVariations(List(versions.scala3), versions.platforms)((only1VersionInIDE) *)
.enablePlugins(GitVersioning, GitBranchPrompt)
.disablePlugins(WelcomePlugin)
.settings(
moduleName := "opinionated-cats-effect",
name := "opinionated-cats-effect",
description := "Opinionated batch of libraries for TypeLevel platform"
)
.settings(settings *)
.settings(versionSchemeSettings *)
.settings(publishSettings *)
.settings(mimaSettings *)
.settings(
libraryDependencies ++= Seq(
"org.typelevel" %%% "cats-effect" % "3.5.4",
"co.fs2" %%% "fs2-core" % "3.10.2"
)
)
addCommandAlias("fullTest", "test")
addCommandAlias("fullCoverageTest", "coverage ; test ; coverageReport ; coverageAggregate")