forked from monix/monix-bio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sbt
380 lines (335 loc) · 13.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
import sbt.url
addCommandAlias("ci-js", s";clean ;coreJS/test")
addCommandAlias("ci-jvm", s";clean ;benchmarks/compile ;coreJVM/test")
addCommandAlias("ci-jvm-mima", s";ci-jvm ;mimaReportBinaryIssues")
addCommandAlias("ci-jvm-all", s";ci-jvm-mima ;docs/docusaurusCreateSite")
val monixVersion = "3.2.1"
val minitestVersion = "2.8.2"
val catsEffectVersion = "2.1.3"
// The Monix version with which we must keep binary compatibility.
// https://github.com/typesafehub/migration-manager/wiki/Sbt-plugin
val monixSeries = "0.1.0"
lazy val `monix-bio` = project.in(file("."))
.settings(skipOnPublishSettings)
.aggregate(coreJVM, coreJS)
.settings(sharedSettings)
lazy val coreJVM = project.in(file("core/jvm"))
.settings(crossSettings ++ crossVersionSharedSources)
.settings(name := "monix-bio")
.enablePlugins(AutomateHeaderPlugin)
.settings(doctestTestSettings)
.settings(mimaSettings)
lazy val coreJS = project.in(file("core/js"))
.settings(crossSettings ++ crossVersionSharedSources)
.enablePlugins(AutomateHeaderPlugin)
.enablePlugins(ScalaJSPlugin)
.settings(scalaJSSettings)
.settings(name := "monix-bio")
lazy val benchmarks = project.in(file("benchmarks"))
.dependsOn(coreJVM)
.enablePlugins(JmhPlugin)
.settings(doNotPublishArtifact)
.settings(crossSettings)
.settings(
libraryDependencies ++= Seq(
"dev.zio" %% "zio" % "1.0.0-RC18-2",
"io.monix" %% "monix-eval" % monixVersion
))
lazy val docs = project
.in(file("monix-bio-docs"))
.settings(
moduleName := "monix-bio-docs",
name := moduleName.value,
sharedSettings,
skipOnPublishSettings,
mdocSettings
)
.dependsOn(coreJVM)
.enablePlugins(DocusaurusPlugin, MdocPlugin, ScalaUnidocPlugin)
lazy val mdocSettings = Seq(
scalacOptions --= Seq("-Xfatal-warnings", "-Ywarn-unused"),
crossScalaVersions := Seq(scalaVersion.value),
unidocProjectFilter in (ScalaUnidoc, unidoc) := inProjects(coreJVM),
target in (ScalaUnidoc, unidoc) := (baseDirectory in LocalRootProject).value / "website" / "static" / "api",
cleanFiles += (target in (ScalaUnidoc, unidoc)).value,
docusaurusCreateSite := docusaurusCreateSite
.dependsOn(unidoc in Compile)
.dependsOn(updateSiteVariables in ThisBuild)
.value,
docusaurusPublishGhpages :=
docusaurusPublishGhpages
.dependsOn(unidoc in Compile)
.dependsOn(updateSiteVariables in ThisBuild)
.value,
scalacOptions in (ScalaUnidoc, unidoc) ++= Seq(
"-doc-source-url", s"https://github.com/monix/monix-bio/tree/v${version.value}€{FILE_PATH}.scala",
"-sourcepath", baseDirectory.in(LocalRootProject).value.getAbsolutePath,
"-doc-title", "Monix BIO",
"-doc-version", s"v${version.value}",
"-groups"
),
// Exclude monix.*.internal from ScalaDoc
sources in (ScalaUnidoc, unidoc) ~= (_ filterNot { file =>
// Exclude all internal Java files from documentation
file.getCanonicalPath matches "^.*monix.+?internal.*?\\.java$"
}),
)
def minorVersion(version: String): String = {
val (major, minor) =
CrossVersion.partialVersion(version).get
s"$major.$minor"
}
val updateSiteVariables = taskKey[Unit]("Update site variables")
updateSiteVariables in ThisBuild := {
val file =
(baseDirectory in LocalRootProject).value / "website" / "variables.js"
val variables =
Map[String, String](
"organization" -> (organization in LocalRootProject).value,
"coreModuleName" -> (moduleName in coreJVM).value,
"latestVersion" -> version.value,
"scalaPublishVersions" -> {
val minorVersions = (crossScalaVersions in coreJVM).value.map(minorVersion)
if (minorVersions.size <= 2) minorVersions.mkString(" and ")
else minorVersions.init.mkString(", ") ++ " and " ++ minorVersions.last
}
)
val fileHeader =
"// Generated by sbt. Do not edit directly."
val fileContents =
variables.toList
.sortBy { case (key, _) => key }
.map { case (key, value) => s" $key: '$value'" }
.mkString(s"$fileHeader\nmodule.exports = {\n", ",\n", "\n};\n")
IO.write(file, fileContents)
}
lazy val contributors = Seq(
"Avasil" -> "Piotr Gawrys"
)
lazy val doNotPublishArtifact = Seq(
publishArtifact := false,
publishArtifact in (Compile, packageDoc) := false,
publishArtifact in (Compile, packageSrc) := false,
publishArtifact in (Compile, packageBin) := false
)
// General Settings
lazy val sharedSettings = Seq(
organization := "io.monix",
scalaVersion := "2.13.1",
crossScalaVersions := Seq("2.12.10", "2.13.1"),
scalacOptions ++= Seq(
// warnings
"-unchecked", // able additional warnings where generated code depends on assumptions
"-deprecation", // emit warning for usages of deprecated APIs
"-feature", // emit warning usages of features that should be imported explicitly
// Features enabled by default
"-language:higherKinds",
"-language:implicitConversions",
"-language:experimental.macros",
),
// More version specific compiler options
scalacOptions ++= (CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, v)) if v <= 12 =>
Seq(
"-Ypartial-unification",
"-Xfuture",
"-Yno-adapted-args",
"-Ywarn-unused-import"
)
case _ =>
Seq(
"-Ywarn-unused:imports",
// Replaces macro-paradise in Scala 2.13
"-Ymacro-annotations"
)
}),
// Linter
scalacOptions ++= Seq(
// Turns all warnings into errors ;-)
// "-Xfatal-warnings",
// Enables linter options
"-Xlint:adapted-args", // warn if an argument list is modified to match the receiver
"-Xlint:nullary-unit", // warn when nullary methods return Unit
"-Xlint:nullary-override", // warn when non-nullary `def f()' overrides nullary `def f'
"-Xlint:infer-any", // warn when a type argument is inferred to be `Any`
"-Xlint:missing-interpolator", // a string literal appears to be missing an interpolator id
"-Xlint:doc-detached", // a ScalaDoc comment appears to be detached from its element
"-Xlint:private-shadow", // a private field (or class parameter) shadows a superclass field
"-Xlint:type-parameter-shadow", // a local type parameter shadows a type already in scope
"-Xlint:poly-implicit-overload", // parameterized overloaded implicit methods are not visible as view bounds
"-Xlint:option-implicit", // Option.apply used implicit view
"-Xlint:delayedinit-select", // Selecting member of DelayedInit
"-Xlint:package-object-classes", // Class or object defined in package object
),
scalacOptions ++= (CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, majorVersion)) if majorVersion <= 12 =>
Seq(
"-Xlint:inaccessible", // warn about inaccessible types in method signatures
"-Xlint:by-name-right-associative", // By-name parameter of right associative operator
"-Xlint:unsound-match" // Pattern match may not be typesafe
)
case _ =>
Seq.empty
}),
// Silence all warnings from src_managed files
scalacOptions += "-P:silencer:pathFilters=.*[/]src_managed[/].*",
// Turning off fatal warnings for ScalaDoc, otherwise we can't release.
scalacOptions in (Compile, doc) ~= (_ filterNot (_ == "-Xfatal-warnings")),
addCompilerPlugin("org.typelevel" % "kind-projector" % "0.11.0" cross CrossVersion.full),
addCompilerPlugin("com.github.ghik" % "silencer-plugin" % "1.6.0" cross CrossVersion.full),
libraryDependencies ++= Seq(
"io.monix" %%% "monix-catnap" % monixVersion,
"io.monix" %%% "minitest" % minitestVersion % Test,
"io.monix" %%% "minitest-laws" % minitestVersion % Test,
"org.typelevel" %%% "cats-effect-laws" % catsEffectVersion % Test
),
// ScalaDoc settings
autoAPIMappings := true,
apiURL := Some(url("https://monix.github.io/monix-bio/api/")),
apiMappings ++= {
val cp: Seq[Attributed[File]] = (fullClasspath in Compile).value
def findManagedDependency(organization: String, name: String): File = {
( for {
entry <- cp
module <- entry.get(moduleID.key)
if module.organization == organization
if module.name.startsWith(name)
} yield entry.data
).head
}
Map(
findManagedDependency("io.monix","monix-execution") -> url("https://monix.io/api/3.1/"),
findManagedDependency("io.monix","monix-catnap") -> url("https://monix.io/api/3.1/"),
findManagedDependency("org.typelevel","cats-effect") -> url("https://typelevel.org/cats-effect/api/")
)
},
scalacOptions in ThisBuild ++= Seq(
// Note, this is used by the doc-source-url feature to determine the
// relative path of a given source file. If it's not a prefix of a the
// absolute path of the source file, the absolute path of that file
// will be put into the FILE_SOURCE variable, which is
// definitely not what we want.
"-sourcepath", file(".").getAbsolutePath.replaceAll("[.]$", "")
),
resolvers ++= Seq(
"Typesafe Releases" at "https://repo.typesafe.com/typesafe/releases",
Resolver.sonatypeRepo("releases")
),
// https://github.com/sbt/sbt/issues/2654
incOptions := incOptions.value.withLogRecompileOnMacro(false),
// -- Settings meant for deployment on oss.sonatype.org
sonatypeProfileName := organization.value,
credentials += Credentials(
"Sonatype Nexus Repository Manager",
"oss.sonatype.org",
sys.env.getOrElse("SONATYPE_USER", ""),
sys.env.getOrElse("SONATYPE_PASS", "")
),
publishMavenStyle := true,
publishTo := Some(
if (isSnapshot.value)
Opts.resolver.sonatypeSnapshots
else
Opts.resolver.sonatypeStaging
),
isSnapshot := version.value endsWith "SNAPSHOT",
publishArtifact in Test := false,
pomIncludeRepository := { _ => false }, // removes optional dependencies
licenses := Seq("APL2" -> url("http://www.apache.org/licenses/LICENSE-2.0.txt")),
homepage := Some(url("https://monix.io")),
testFrameworks := Seq(new TestFramework("minitest.runner.Framework")),
headerLicense := Some(HeaderLicense.Custom(
"""|Copyright (c) 2019-2020 by The Monix Project Developers.
|See the project homepage at: https://monix.io
|
|Licensed under the Apache License, Version 2.0 (the "License");
|you may not use this file except in compliance with the License.
|You may obtain a copy of the License at
|
| http://www.apache.org/licenses/LICENSE-2.0
|
|Unless required by applicable law or agreed to in writing, software
|distributed under the License is distributed on an "AS IS" BASIS,
|WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|See the License for the specific language governing permissions and
|limitations under the License."""
.stripMargin)),
scmInfo := Some(
ScmInfo(
url("https://github.com/monix/monix-bio"),
"scm:git@github.com:monix/monix-bio.git"
)),
developers := List(
Developer(
id="Avasil",
name="Piotr Gawrys",
email="pgawrys2@gmail.com",
url=url("https://github.com/Avasil")
))
)
lazy val crossSettings = sharedSettings ++ Seq(
unmanagedSourceDirectories in Compile += {
baseDirectory.value.getParentFile / "shared" / "src" / "main" / "scala"
},
unmanagedSourceDirectories in Test += {
baseDirectory.value.getParentFile / "shared" / "src" / "test" / "scala"
}
)
def scalaPartV = Def setting (CrossVersion partialVersion scalaVersion.value)
lazy val crossVersionSharedSources: Seq[Setting[_]] =
Seq(Compile, Test).map { sc =>
(unmanagedSourceDirectories in sc) ++= {
(unmanagedSourceDirectories in sc).value.flatMap { dir =>
Seq(
scalaPartV.value match {
case Some((2, y)) if y == 11 => new File(dir.getPath + "_2.11")
case Some((2, y)) if y == 12 => new File(dir.getPath + "_2.12")
case Some((2, y)) if y >= 13 => new File(dir.getPath + "_2.13")
},
scalaPartV.value match {
case Some((2, n)) if n >= 12 => new File(dir.getPath + "_2.12+")
case _ => new File(dir.getPath + "_2.12-")
},
scalaPartV.value match {
case Some((2, n)) if n >= 13 => new File(dir.getPath + "_2.13+")
case _ => new File(dir.getPath + "_2.13-")
},
)
}
}
}
lazy val scalaJSSettings = Seq(
// Use globally accessible (rather than local) source paths in JS source maps
scalacOptions += {
val tagOrHash =
if (isSnapshot.value) git.gitHeadCommit.value.get
else s"v${git.baseVersion.value}"
val l = (baseDirectory in LocalRootProject).value.toURI.toString
val g = s"https://raw.githubusercontent.com/monix/monix-bio/$tagOrHash/"
s"-P:scalajs:mapSourceURI:$l->$g"
}
)
val mimaSettings = Seq(
mimaPreviousArtifacts := Set("io.monix" %% "monix-bio" % monixSeries),
mimaBinaryIssueFilters ++= MimaFilters.changes
)
// https://github.com/lightbend/mima/pull/289
mimaFailOnNoPrevious in ThisBuild := false
lazy val docsMappingsAPIDir =
settingKey[String]("Name of subdirectory in site target directory for api docs")
lazy val doctestTestSettings = Seq(
doctestTestFramework := DoctestTestFramework.Minitest,
doctestIgnoreRegex := Some(s".*BIOApp.scala"),
doctestOnlyCodeBlocksMode := true
)
lazy val skipOnPublishSettings = Seq(
skip in publish := true,
publish := (()),
publishLocal := (()),
publishArtifact := false,
publishTo := None
)
/* The BaseVersion setting represents the in-development (upcoming) version,
* as an alternative to SNAPSHOTS.
*/
git.baseVersion := (version in ThisBuild).value