-
Notifications
You must be signed in to change notification settings - Fork 30
/
build.sbt
349 lines (322 loc) · 11.6 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.softwaremill.UpdateVersionInDocs
import sbt.Def
import sbt.Reference.display
import com.softwaremill.SbtSoftwareMillCommon.commonSmlBuildSettings
import com.softwaremill.Publish.{ossPublishSettings, updateDocs}
import complete.DefaultParsers._
val scala212 = "2.12.16"
val scala213 = "2.13.8"
val scala3 = "3.2.2"
val scalaIdeaVersion = scala3 // the version for which to import sources into intellij
val scalatestVersion = "3.2.12"
val specs2Version = "4.16.1"
val smlTaggingVersion = "2.3.3"
val scopesDescription = "Scala version can be: 2.12, 2.13, 3; platform: JVM, JS, Native"
val compileScoped =
inputKey[Unit](
s"Compiles sources in the given scope. Usage: compileScoped [scala version] [platform]. $scopesDescription"
)
val testScoped =
inputKey[Unit](s"Run tests in the given scope. Usage: testScoped [scala version] [platform]. $scopesDescription")
lazy val commonSettings: Seq[Def.Setting[_]] = commonSmlBuildSettings ++ ossPublishSettings ++ Seq(
organization := "com.softwaremill.diffx",
scmInfo := Some(ScmInfo(url("https://github.com/softwaremill/diffx"), "git@github.com:softwaremill/diffx.git")),
ideSkipProject := (scalaVersion.value != scalaIdeaVersion) || thisProjectRef.value.project.contains("JS"),
mimaPreviousArtifacts := Set.empty, // we only use MiMa for `core` for now, using enableMimaSettings
updateDocs := Def.taskDyn {
val files1 = UpdateVersionInDocs(sLog.value, organization.value, version.value)
Def.task {
(docs.jvm(scala213) / mdoc).toTask("").value
files1 ++ Seq(file("generated-docs/out"))
}
}.value
)
val compileDocs: TaskKey[Unit] = taskKey[Unit]("Compiles docs module throwing away its output")
compileDocs := {
(docs.jvm(scala213) / mdoc).toTask(" --out target/diffx-docs").value
}
val versioningSchemeSettings = Seq(versionScheme := Some("early-semver"))
val enableMimaSettings = Seq(
mimaPreviousArtifacts := {
val previous = previousStableVersion.value
println(s"[info] Not a M or RC version, using previous version for MiMa check: $previous")
previous.map(organization.value %% moduleName.value % _).toSet
}
)
val versionSpecificScalaSources = {
Compile / unmanagedSourceDirectories := {
val current = (Compile / unmanagedSourceDirectories).value
val sv = (Compile / scalaVersion).value
val baseDirectory = (Compile / scalaSource).value
val suffixes = CrossVersion.partialVersion(sv) match {
case Some((2, 13)) => List("2", "2.13+")
case Some((2, _)) => List("2", "2.13-")
case Some((3, _)) => List("3")
case _ => Nil
}
val versionSpecificSources = suffixes.map(s => new File(baseDirectory.getAbsolutePath + "-" + s))
versionSpecificSources ++ current
}
}
lazy val core = (projectMatrix in file("core"))
.settings(commonSettings)
.settings(versioningSchemeSettings)
.settings(
name := "diffx-core",
libraryDependencies ++= {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((3, _)) =>
Seq(
"com.softwaremill.magnolia1_3" %%% "magnolia" % "1.1.4"
)
case _ =>
Seq(
"com.softwaremill.magnolia1_2" %%% "magnolia" % "1.1.4",
"org.scala-lang" % "scala-reflect" % scalaVersion.value % Provided
)
}
},
libraryDependencies ++= Seq(
"org.scalatest" %%% "scalatest-flatspec" % scalatestVersion % Test,
"org.scalatest" %%% "scalatest-freespec" % scalatestVersion % Test,
"org.scalatest" %%% "scalatest-shouldmatchers" % scalatestVersion % Test,
"io.github.cquiroz" %%% "scala-java-time" % "2.4.0" % Test
),
versionSpecificScalaSources,
scalacOptions ++= (CrossVersion.partialVersion(scalaVersion.value) match {
case Some((3, _)) => Seq("-Xmax-inlines:64")
case _ => Seq()
})
)
.jvmPlatform(
scalaVersions = List(scala212, scala213, scala3),
settings = enableMimaSettings
)
.jsPlatform(
scalaVersions = List(scala212, scala213, scala3),
libraryDependencies += ("org.scala-js" %%% "scalajs-fake-insecure-java-securerandom" % "1.0.0")
.cross(CrossVersion.for3Use2_13) % Test
)
lazy val scalatestMust = (projectMatrix in file("scalatest-must"))
.settings(commonSettings)
.settings(
name := "diffx-scalatest-must",
libraryDependencies ++= Seq(
"org.scalatest" %%% "scalatest-mustmatchers" % scalatestVersion,
"org.scalatest" %%% "scalatest-matchers-core" % scalatestVersion,
"org.scalatest" %%% "scalatest-flatspec" % scalatestVersion % Test
)
)
.dependsOn(core)
.jvmPlatform(
scalaVersions = List(scala212, scala213, scala3)
)
.jsPlatform(
scalaVersions = List(scala212, scala213, scala3)
)
lazy val scalatestShould = (projectMatrix in file("scalatest-should"))
.settings(commonSettings)
.settings(
name := "diffx-scalatest-should",
libraryDependencies ++= Seq(
"org.scalatest" %%% "scalatest-shouldmatchers" % scalatestVersion,
"org.scalatest" %%% "scalatest-matchers-core" % scalatestVersion,
"org.scalatest" %%% "scalatest-flatspec" % scalatestVersion % Test
)
)
.dependsOn(core)
.jvmPlatform(
scalaVersions = List(scala212, scala213, scala3)
)
.jsPlatform(
scalaVersions = List(scala212, scala213, scala3)
)
lazy val scalatestLegacy = (projectMatrix in file("scalatest"))
.settings(commonSettings)
.settings(
name := "diffx-scalatest",
libraryDependencies ++= Seq(
"org.scalatest" %%% "scalatest-matchers-core" % scalatestVersion,
"org.scalatest" %%% "scalatest-flatspec" % scalatestVersion % Test,
"org.scalatest" %%% "scalatest-shouldmatchers" % scalatestVersion % Test
)
)
.dependsOn(core)
.jvmPlatform(
scalaVersions = List(scala212, scala213, scala3)
)
.jsPlatform(
scalaVersions = List(scala212, scala213, scala3)
)
lazy val specs2 = (projectMatrix in file("specs2"))
.settings(commonSettings)
.settings(
name := "diffx-specs2",
libraryDependencies ++= Seq(
"org.specs2" %%% "specs2-core" % specs2Version
)
)
.dependsOn(core)
.jvmPlatform(
scalaVersions = List(scala212, scala213)
)
.jsPlatform(
scalaVersions = List(scala212, scala213)
)
lazy val utest = (projectMatrix in file("utest"))
.settings(commonSettings)
.settings(
name := "diffx-utest",
libraryDependencies ++= Seq(
"com.lihaoyi" %%% "utest" % "0.8.0"
),
testFrameworks += new TestFramework("utest.runner.Framework")
)
.dependsOn(core)
.jvmPlatform(
scalaVersions = List(scala212, scala213, scala3)
)
.jsPlatform(
scalaVersions = List(scala212, scala213, scala3)
)
lazy val munit = (projectMatrix in file("munit"))
.settings(commonSettings)
.settings(
name := "diffx-munit",
libraryDependencies ++= Seq(
"org.scalameta" %%% "munit" % "0.7.29"
),
testFrameworks += new TestFramework("munit.Framework")
)
.dependsOn(core)
.jvmPlatform(
scalaVersions = List(scala212, scala213, scala3)
)
.jsPlatform(
scalaVersions = List(scala212, scala213, scala3),
settings = commonSettings ++ Seq(scalaJSLinkerConfig ~= { _.withModuleKind(ModuleKind.CommonJSModule) })
)
lazy val weaver = (projectMatrix in file("weaver"))
.settings(commonSettings)
.settings(
name := "diffx-weaver",
libraryDependencies ++= Seq(
"com.disneystreaming" %%% "weaver-cats" % "0.8.3"
),
testFrameworks += new TestFramework("weaver.framework.CatsEffect")
)
.dependsOn(core)
.jvmPlatform(
scalaVersions = List(scala212, scala213, scala3)
)
.jsPlatform(
scalaVersions = List(scala212, scala213, scala3)
)
lazy val tagging = (projectMatrix in file("tagging"))
.settings(commonSettings)
.settings(
name := "diffx-tagging",
libraryDependencies ++= Seq(
"com.softwaremill.common" %%% "tagging" % smlTaggingVersion,
"org.scalatest" %%% "scalatest-flatspec" % scalatestVersion % Test,
"org.scalatest" %%% "scalatest-shouldmatchers" % scalatestVersion % Test
)
)
.dependsOn(core)
.jvmPlatform(
scalaVersions = List(scala212, scala213, scala3)
)
.jsPlatform(
scalaVersions = List(scala212, scala213, scala3)
)
lazy val cats = (projectMatrix in file("cats"))
.settings(commonSettings)
.settings(
name := "diffx-cats",
libraryDependencies ++= Seq(
"org.typelevel" %%% "cats-core" % "2.8.0",
"org.scalatest" %%% "scalatest-freespec" % scalatestVersion % Test,
"org.scalatest" %%% "scalatest-shouldmatchers" % scalatestVersion % Test
)
)
.dependsOn(core)
.jvmPlatform(
scalaVersions = List(scala212, scala213, scala3)
)
.jsPlatform(
scalaVersions = List(scala212, scala213, scala3)
)
lazy val refined = (projectMatrix in file("refined"))
.settings(commonSettings)
.settings(
name := "diffx-refined",
libraryDependencies ++= Seq(
"eu.timepit" %%% "refined" % "0.10.1",
"org.scalatest" %%% "scalatest-flatspec" % scalatestVersion % Test,
"org.scalatest" %%% "scalatest-shouldmatchers" % scalatestVersion % Test
)
)
.dependsOn(core)
.jvmPlatform(
scalaVersions = List(scala212, scala213, scala3)
)
.jsPlatform(
scalaVersions = List(scala212, scala213, scala3)
)
lazy val docs = (projectMatrix in file("generated-docs")) // important: it must not be docs/
.enablePlugins(MdocPlugin)
.settings(commonSettings)
.settings(
publishArtifact := false,
name := "docs",
libraryDependencies ++= Seq(
"org.typelevel" %% "cats-core" % "2.8.0",
"org.scalatest" %% "scalatest-shouldmatchers" % scalatestVersion
),
mdocIn := file("docs-sources"),
moduleName := "diffx-docs",
mdocVariables := Map(
"VERSION" -> version.value
),
mdocOut := file("generated-docs/out")
)
.dependsOn(core, scalatestShould, specs2, utest, refined, tagging, cats, munit, weaver)
.jvmPlatform(scalaVersions = List(scala213))
val testJVM = taskKey[Unit]("Test JVM projects")
val testJS = taskKey[Unit]("Test JS projects")
val allAggregates =
core.projectRefs ++ scalatestMust.projectRefs ++ scalatestShould.projectRefs ++ scalatestLegacy.projectRefs ++
specs2.projectRefs ++ utest.projectRefs ++ cats.projectRefs ++
refined.projectRefs ++ tagging.projectRefs ++ docs.projectRefs ++ munit.projectRefs ++ weaver.projectRefs
def filterProject(p: String => Boolean) =
ScopeFilter(inProjects(allAggregates.filter(pr => p(display(pr.project))): _*))
def filterByVersionAndPlatform(scalaVersionFilter: String, platformFilter: String) = filterProject { projectName =>
val byPlatform =
if (platformFilter == "JVM") !projectName.contains("JS") && !projectName.contains("Native")
else projectName.contains(platformFilter)
val byVersion = scalaVersionFilter match {
case "2.13" => !projectName.contains("2_12") && !projectName.contains("3")
case "2.12" => projectName.contains("2_12")
case "3" => projectName.contains("3")
}
byPlatform && byVersion && !projectName.contains("finatra")
}
lazy val rootProject = project
.in(file("."))
.settings(commonSettings)
.settings(
publishArtifact := false,
name := "diffx",
scalaVersion := scalaIdeaVersion,
testJVM := (Test / test).all(filterProject(p => !p.contains("JS") && !p.contains("Native"))).value,
testJS := (Test / test).all(filterProject(_.contains("JS"))).value,
compileScoped := Def.inputTaskDyn {
val args = spaceDelimited("<arg>").parsed
Def.taskDyn((Compile / compile).all(filterByVersionAndPlatform(args.head, args(1))))
}.evaluated,
testScoped := Def.inputTaskDyn {
val args = spaceDelimited("<arg>").parsed
Def.taskDyn((Test / test).all(filterByVersionAndPlatform(args.head, args(1))))
}.evaluated
)
.aggregate(allAggregates: _*)