-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sbt
332 lines (288 loc) · 12.8 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
import BuildKeys._
import Boilerplate._
import sbtcrossproject.CrossPlugin.autoImport.{crossProject, CrossType}
import sbtcrossproject.CrossProject
// ---------------------------------------------------------------------------
// Commands
/* We have no other way to target only JVM or JS projects in tests. */
lazy val aggregatorIDs = Seq("xml")
addCommandAlias("ci-jvm", ";" + aggregatorIDs.map(id => s"${id}JVM/clean ;${id}JVM/test:compile ;${id}JVM/test").mkString(";"))
addCommandAlias("ci-js", ";" + aggregatorIDs.map(id => s"${id}JS/clean ;${id}JS/test:compile ;${id}JS/test").mkString(";"))
addCommandAlias("ci-package", ";scalafmtCheckAll ;package")
addCommandAlias("ci-doc", ";unidoc ;site/makeMicrosite")
addCommandAlias("ci", ";project root ;reload ;+scalafmtCheckAll ;+ci-jvm ;+ci-js ;+package ;ci-doc")
addCommandAlias("release", ";+clean ;ci-release ;unidoc ;site/publishMicrosite")
// ---------------------------------------------------------------------------
// Dependencies
/** Standard FP library for Scala:
* [[https://typelevel.org/cats/]]
*/
val CatsVersion = "2.2.0"
/** FP library for describing side-effects:
* [[https://typelevel.org/cats-effect/]]
*/
val CatsEffectVersion = "2.2.0"
/** First-class support for type-classes:
* [[https://github.com/typelevel/simulacrum]]
*/
val SimulacrumVersion = "1.0.0"
/** For macros that are supported on older Scala versions.
* Not needed starting with Scala 2.13.
*/
val MacroParadiseVersion = "2.1.1"
/** Library for unit-testing:
* [[https://github.com/monix/minitest/]]
* - [[https://github.com/scalatest/scalatest]]
* - [[https://github.com/scalatest/scalatestplus-scalacheck/]]
*/
val ScalaTestVersion = "3.2.2"
val ScalaTestPlusVersion = "3.2.2.0"
/** Library for property-based testing:
* [[https://www.scalacheck.org/]]
*/
val ScalaCheckVersion = "1.14.3"
/** Compiler plugin for working with partially applied types:
* [[https://github.com/typelevel/kind-projector]]
*/
val KindProjectorVersion = "0.11.0"
/** Compiler plugin for fixing "for comprehensions" to do desugaring w/o `withFilter`:
* [[https://github.com/typelevel/kind-projector]]
*/
val BetterMonadicForVersion = "0.3.1"
/** Compiler plugin for silencing compiler warnings:
* [[https://github.com/ghik/silencer]]
*/
val SilencerVersion = "1.7.1"
/** Used for publishing the microsite:
* [[https://github.com/47degrees/github4s]]
*/
val GitHub4sVersion = "0.25.0"
/**
* Defines common plugins between all projects.
*/
def defaultPlugins: Project ⇒ Project = pr => {
val withCoverage = sys.env.getOrElse("SBT_PROFILE", "") match {
case "coverage" => pr
case _ => pr.disablePlugins(scoverage.ScoverageSbtPlugin)
}
withCoverage
.enablePlugins(AutomateHeaderPlugin)
.enablePlugins(GitBranchPrompt)
}
lazy val sharedSettings = Seq(
projectTitle := "Vesper Codecs",
projectWebsiteRootURL := "https://ing-vesper.github.io/",
projectWebsiteBasePath := "/vesper-codecs/",
githubOwnerID := "ing-vesper",
githubRelativeRepositoryID := "vesper-codecs",
organization := "io.github.ing-vesper",
scalaVersion := "2.13.3",
crossScalaVersions := Seq("2.12.12", "2.13.3"),
// More version specific compiler options
scalacOptions ++= (CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, v)) if v >= 13 =>
Seq(
// Replaces macro-paradise in Scala 2.13
// No
//"-Ymacro-annotations",
)
case _ =>
Seq.empty
}),
// Turning off fatal warnings for doc generation
scalacOptions.in(Compile, doc) ~= filterConsoleScalacOptions,
// Silence all warnings from src_managed files
scalacOptions += "-P:silencer:pathFilters=.*[/]src_managed[/].*",
addCompilerPlugin("org.typelevel" % "kind-projector" % KindProjectorVersion cross CrossVersion.full),
addCompilerPlugin("com.olegpy" %% "better-monadic-for" % BetterMonadicForVersion),
addCompilerPlugin("com.github.ghik" % "silencer-plugin" % SilencerVersion cross CrossVersion.full),
// ScalaDoc settings
autoAPIMappings := true,
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("[.]$", "")
),
// https://github.com/sbt/sbt/issues/2654
incOptions := incOptions.value.withLogRecompileOnMacro(false),
// ---------------------------------------------------------------------------
// Options for testing
logBuffered in Test := false,
logBuffered in IntegrationTest := false,
// ---------------------------------------------------------------------------
// Options meant for publishing on Maven Central
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(projectWebsiteFullURL.value)),
headerLicense := Some(HeaderLicense.Custom(
s"""|Copyright (c) 2020 the ${projectTitle.value} contributors.
|See the project homepage at: ${projectWebsiteFullURL.value}
|
|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(s"https://github.com/${githubFullRepositoryID.value}"),
s"scm:git@github.com:${githubFullRepositoryID.value}.git"
)),
developers := List(
Developer(
id="alexelcu",
name="Alexandru Nedelcu",
email="noreply@alexn.org",
url=url("https://alexn.org")
)),
// -- Settings meant for deployment on oss.sonatype.org
sonatypeProfileName := organization.value,
)
/**
* Shared configuration across all sub-projects with actual code to be published.
*/
def defaultCrossProjectConfiguration(pr: CrossProject) = {
val sharedJavascriptSettings = Seq(
coverageExcludedFiles := ".*",
// Use globally accessible (rather than local) source paths in JS source maps
scalacOptions += {
val tagOrHash = {
val ver = s"v${version.value}"
if (isSnapshot.value)
git.gitHeadCommit.value.getOrElse(ver)
else
ver
}
val l = (baseDirectory in LocalRootProject).value.toURI.toString
val g = s"https://raw.githubusercontent.com/${githubFullRepositoryID.value}/$tagOrHash/"
s"-P:scalajs:mapSourceURI:$l->$g"
},
// Needed in order to publish for multiple Scala.js versions:
// https://github.com/olafurpg/sbt-ci-release#how-do-i-publish-cross-built-scalajs-projects
skip.in(publish) := customScalaJSVersion.isEmpty,
)
val sharedJVMSettings = Seq(
// Needed in order to publish for multiple Scala.js versions:
// https://github.com/olafurpg/sbt-ci-release#how-do-i-publish-cross-built-scalajs-projects
skip.in(publish) := customScalaJSVersion.isDefined,
)
pr.configure(defaultPlugins)
.settings(sharedSettings)
.jsSettings(sharedJavascriptSettings)
.jvmSettings(doctestTestSettings(DoctestTestFramework.ScalaTest))
.jvmSettings(sharedJVMSettings)
.settings(crossVersionSharedSources)
.settings(requiredMacroCompatDeps(MacroParadiseVersion))
.settings(filterOutMultipleDependenciesFromGeneratedPomXml(
"groupId" -> "org.scoverage".r :: Nil,
"groupId" -> "org.typelevel".r :: "artifactId" -> "simulacrum".r :: Nil,
))
}
lazy val root = project.in(file("."))
.enablePlugins(ScalaUnidocPlugin)
.aggregate(xmlJVM, xmlJS)
.configure(defaultPlugins)
.settings(sharedSettings)
.settings(doNotPublishArtifact)
.settings(unidocSettings(xmlJVM))
.settings(
// Try really hard to not execute tasks in parallel ffs
Global / concurrentRestrictions := Tags.limitAll(1) :: Nil,
)
lazy val site = project.in(file("site"))
.disablePlugins(MimaPlugin)
.enablePlugins(MicrositesPlugin)
.enablePlugins(MdocPlugin)
.settings(sharedSettings)
.settings(doNotPublishArtifact)
.dependsOn(xmlJVM)
.settings {
import microsites._
Seq(
micrositeName := projectTitle.value,
micrositeDescription := "Scala library for encoding/decoding XML documents.",
micrositeAuthor := "Alexandru Nedelcu",
micrositeTwitterCreator := "@alexelcu",
micrositeGithubOwner := githubOwnerID.value,
micrositeGithubRepo := githubRelativeRepositoryID.value,
micrositeUrl := projectWebsiteRootURL.value.replaceAll("[/]+$", ""),
micrositeBaseUrl := projectWebsiteBasePath.value.replaceAll("[/]+$", ""),
micrositeDocumentationUrl := s"${projectWebsiteFullURL.value.replaceAll("[/]+$", "")}/${docsMappingsAPIDir.value}/",
micrositeGitterChannelUrl := githubFullRepositoryID.value,
micrositeFooterText := None,
micrositeHighlightTheme := "atom-one-light",
micrositePalette := Map(
"brand-primary" -> "#3e5b95",
"brand-secondary" -> "#294066",
"brand-tertiary" -> "#2d5799",
"gray-dark" -> "#49494B",
"gray" -> "#7B7B7E",
"gray-light" -> "#E5E5E6",
"gray-lighter" -> "#F4F3F4",
"white-color" -> "#FFFFFF"
),
micrositeCompilingDocsTool := WithMdoc,
fork in mdoc := true,
scalacOptions.in(Tut) ~= filterConsoleScalacOptions,
libraryDependencies += "com.47deg" %% "github4s" % GitHub4sVersion,
micrositePushSiteWith := GitHub4s,
micrositeGithubToken := sys.env.get("GITHUB_TOKEN"),
micrositeExtraMdFilesOutput := (resourceManaged in Compile).value / "jekyll",
micrositeConfigYaml := ConfigYml(
yamlPath = Some((resourceDirectory in Compile).value / "microsite" / "_config.yml")
),
micrositeExtraMdFiles := Map(
file("README.md") -> ExtraMdFileConfig("index.md", "page", Map("title" -> "Home", "section" -> "home", "position" -> "100")),
file("CHANGELOG.md") -> ExtraMdFileConfig("CHANGELOG.md", "page", Map("title" -> "Change Log", "section" -> "changelog", "position" -> "101")),
file("CONTRIBUTING.md") -> ExtraMdFileConfig("CONTRIBUTING.md", "page", Map("title" -> "Contributing", "section" -> "contributing", "position" -> "102")),
file("CODE_OF_CONDUCT.md") -> ExtraMdFileConfig("CODE_OF_CONDUCT.md", "page", Map("title" -> "Code of Conduct", "section" -> "code of conduct", "position" -> "103")),
file("LICENSE.md") -> ExtraMdFileConfig("LICENSE.md", "page", Map("title" -> "License", "section" -> "license", "position" -> "104")),
),
docsMappingsAPIDir := s"api",
addMappingsToSiteDir(mappings in (ScalaUnidoc, packageDoc) in root, docsMappingsAPIDir),
sourceDirectory in Compile := baseDirectory.value / "src",
sourceDirectory in Test := baseDirectory.value / "test",
mdocIn := (sourceDirectory in Compile).value / "mdoc",
run in Compile := {
import scala.sys.process._
val s: TaskStreams = streams.value
val shell: Seq[String] = if (sys.props("os.name").contains("Windows")) Seq("cmd", "/c") else Seq("bash", "-c")
val jekyllServe: String = s"jekyll serve --open-url --baseurl ${(micrositeBaseUrl in Compile).value}"
s.log.info("Running Jekyll...")
Process(shell :+ jekyllServe, (micrositeExtraMdFilesOutput in Compile).value) !
},
)
}
lazy val xml = crossProject(JSPlatform, JVMPlatform)
.crossType(CrossType.Full)
.in(file("xml"))
.configureCross(defaultCrossProjectConfiguration)
.settings(
name := "vesper-codecs-xml",
libraryDependencies ++= Seq(
"org.typelevel" %%% "simulacrum" % SimulacrumVersion % Provided,
"org.typelevel" %%% "cats-core" % CatsVersion,
"org.typelevel" %%% "cats-effect" % CatsEffectVersion,
// For testing
"org.scalatest" %%% "scalatest" % ScalaTestVersion % Test,
"org.scalatestplus" %%% "scalacheck-1-14" % ScalaTestPlusVersion % Test,
"org.scalacheck" %%% "scalacheck" % ScalaCheckVersion % Test,
"org.typelevel" %%% "cats-laws" % CatsVersion % Test,
"org.typelevel" %%% "cats-effect-laws" % CatsEffectVersion % Test,
),
)
lazy val xmlJVM = xml.jvm
lazy val xmlJS = xml.js
// Reloads build.sbt changes whenever detected
Global / onChangedBuildSource := ReloadOnSourceChanges