-
Notifications
You must be signed in to change notification settings - Fork 18
/
build.sbt
272 lines (239 loc) · 6.77 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
import scala.sys.process._
/// variables
val groupId = "eu.timepit"
val projectName = "crjdt"
val rootPkg = s"$groupId.$projectName"
val gitHubOwner = "fthomas"
val gitPubUrl = s"https://github.com/$gitHubOwner/$projectName.git"
val gitDevUrl = s"[email protected]:$gitHubOwner/$projectName.git"
val modulesDir = "modules"
val catsVersion = "2.0.0"
val circeVersion = "0.11.2"
val scalaCheckVersion = "1.15.0"
val allSubprojects = Seq("core", "circe")
val allSubprojectsJVM = allSubprojects.map(_ + "JVM")
val allSubprojectsJS = allSubprojects.map(_ + "JS")
/// projects
lazy val root = project
.in(file("."))
.aggregate(coreJVM, coreJS, circeJVM, circeJS, docs)
.settings(commonSettings)
.settings(noPublishSettings)
.settings(
console := console.in(coreJVM, Compile).value,
console.in(Test) := console.in(coreJVM, Test).value
)
lazy val core = crossProject
.crossType(CrossType.Pure)
.in(file(s"$modulesDir/core"))
.settings(moduleName := s"$projectName-core")
.settings(commonSettings: _*)
.settings(publishSettings: _*)
.jsSettings(commonJsSettings: _*)
.settings(
libraryDependencies ++= Seq(
"org.typelevel" %%% "cats-core" % catsVersion,
"org.typelevel" %%% "cats-laws" % catsVersion % "test",
"org.scalacheck" %%% "scalacheck" % scalaCheckVersion % "test"
)
)
lazy val coreJVM = core.jvm
lazy val coreJS = core.js
lazy val circe = crossProject
.crossType(CrossType.Pure)
.in(file(s"$modulesDir/circe"))
.dependsOn(core)
.settings(moduleName := s"$projectName-circe")
.settings(commonSettings: _*)
.settings(publishSettings: _*)
.jsSettings(commonJsSettings: _*)
.settings(
libraryDependencies ++= Seq(
"io.circe" %%% "circe-core" % circeVersion,
"io.circe" %%% "circe-testing" % circeVersion % "test",
"org.scalacheck" %%% "scalacheck" % scalaCheckVersion % "test"
)
)
lazy val circeJVM = circe.jvm
lazy val circeJS = circe.js
lazy val docs = project
.in(file(s"$modulesDir/docs"))
.enablePlugins(MicrositesPlugin)
.enablePlugins(ScalaUnidocPlugin)
.settings(commonSettings)
.settings(noPublishSettings)
.settings(micrositeSettings)
.settings(
Def.settings(
unidocProjectFilter in (ScalaUnidoc, unidoc) :=
inAnyProject -- inProjects(allSubprojectsJS.map(LocalProject.apply): _*)
)
)
/// settings
lazy val commonSettings = Def.settings(
metadataSettings,
compileSettings,
scaladocSettings,
releaseSettings,
styleSettings,
miscSettings
)
lazy val commonJsSettings = Def.settings()
lazy val metadataSettings = Def.settings(
name := projectName,
description := "A conflict-free replicated JSON datatype (CRDT) in Scala",
organization := groupId,
homepage := Some(url(s"https://github.com/$gitHubOwner/$projectName")),
startYear := Some(2016),
licenses := Seq(
"Apache-2.0" -> url("https://www.apache.org/licenses/LICENSE-2.0")
),
scmInfo := Some(
ScmInfo(
homepage.value.get,
s"scm:git:$gitPubUrl",
Some(s"scm:git:$gitDevUrl")
)
),
developers := List(
Developer(
id = "fthomas",
name = "Frank S. Thomas",
email = "",
url("https://github.com/fthomas")
)
),
bintrayPackageLabels := Seq("JSON", "CRDT", "Scala")
)
lazy val compileSettings = Def.settings(
scalacOptions ++= Seq(
"-deprecation",
"-encoding",
"UTF-8",
"-feature",
"-language:existentials",
"-language:experimental.macros",
"-language:higherKinds",
"-language:implicitConversions",
"-unchecked",
"-Xfatal-warnings",
"-Xfuture",
"-Xlint",
"-Yno-adapted-args",
"-Ywarn-numeric-widen",
"-Ywarn-unused-import",
"-Ywarn-value-discard"
),
scalacOptions in (Compile, console) -= "-Ywarn-unused-import",
scalacOptions in (Test, console) -= "-Ywarn-unused-import"
)
lazy val scaladocSettings = Def.settings(
scalacOptions in (Compile, doc) ++= Seq(
"-doc-source-url",
scmInfo.value.get.browseUrl + "/tree/master€{FILE_PATH}.scala",
"-sourcepath",
baseDirectory.in(LocalRootProject).value.getAbsolutePath
),
autoAPIMappings := true,
apiURL := Some(url(s"http://$gitHubOwner.github.io/$projectName/latest/api/"))
)
lazy val publishSettings = Def.settings(
publishMavenStyle := true,
pomIncludeRepository := { _ => false }
)
lazy val noPublishSettings = Def.settings(
publish := {},
publishLocal := {},
publishArtifact := false
)
lazy val releaseSettings = {
import sbtrelease.ReleaseStateTransformations._
lazy val updateVersionInReadme: ReleaseStep = { st: State =>
val extracted = Project.extract(st)
val newVersion = extracted.get(version)
val oldVersion = extracted.get(latestVersion)
val readme = "README.md"
val oldContent = IO.read(file(readme))
val newContent = oldContent.replaceAll(oldVersion, newVersion)
IO.write(file(readme), newContent)
s"git add $readme" !! st.log
st
}
Def.settings(
releaseCrossBuild := true,
releasePublishArtifactsAction := PgpKeys.publishSigned.value,
releaseVcsSign := true,
releaseProcess := Seq[ReleaseStep](
checkSnapshotDependencies,
inquireVersions,
runClean,
runTest,
setReleaseVersion,
updateVersionInReadme,
commitReleaseVersion,
tagRelease,
publishArtifacts,
releaseStepTask(publishMicrosite in LocalProject("docs")),
setLatestVersion,
setNextVersion,
commitNextVersion,
pushChanges
)
)
}
lazy val styleSettings = Def.settings()
lazy val miscSettings = Def.settings(
initialCommands += s"""
import $rootPkg.core._
import $rootPkg.core.syntax._
""",
initialCommands in Test += s"""
import $rootPkg.core.arbitrary._
import org.scalacheck.Arbitrary
"""
)
lazy val micrositeSettings = Def.settings(
micrositeName := projectName,
micrositeBaseUrl := projectName,
micrositeDocumentationUrl := "latest/api",
micrositeGithubOwner := gitHubOwner,
micrositeGithubRepo := projectName,
micrositeExtraMdFiles := Map(
file("README.md") -> microsites.ExtraMdFileConfig("index.md", "home")
),
organizationName := "Frank S. Thomas",
addMappingsToSiteDir(
mappings in (ScalaUnidoc, packageDoc),
micrositeDocumentationUrl
)
)
/// commands
def addCommandsAlias(name: String, cmds: Seq[String]) =
addCommandAlias(name, cmds.mkString(";", ";", ""))
addCommandsAlias("testJS", allSubprojectsJS.map(_ + "/test"))
addCommandsAlias("testJVM", allSubprojectsJVM.map(_ + "/test"))
addCommandsAlias(
"validateJS",
Seq(
"clean",
"testJS"
)
)
addCommandsAlias(
"validateJVM",
Seq(
"clean",
"scalafmtCheck",
"scalafmtSbtCheck",
"test:scalafmtCheck",
"coverage",
"testJVM",
"coverageReport",
"coverageOff",
"unidoc"
)
)
addCommandsAlias(
"syncMavenCentral",
allSubprojectsJVM.map(_ + "/bintraySyncMavenCentral")
)