-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.sbt
441 lines (365 loc) · 14.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
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
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
import sbtcrossproject.CrossProject
ThisBuild / scalaVersion := props.ProjectScalaVersion
ThisBuild / organization := props.Org
ThisBuild / organizationName := "Kevin's Code"
ThisBuild / crossScalaVersions := props.CrossScalaVersions
ThisBuild / developers := List(
Developer(
props.GitHubUsername,
"Kevin Lee",
url(s"https://github.com/${props.GitHubUsername}"),
)
)
ThisBuild / homepage := Some(url(s"https://github.com/${props.GitHubUsername}/${props.RepoName}"))
ThisBuild / scmInfo :=
Some(
ScmInfo(
url(s"https://github.com/${props.GitHubUsername}/${props.RepoName}"),
s"[email protected]:${props.GitHubUsername}/${props.RepoName}.git",
)
)
ThisBuild / licenses := props.licenses
ThisBuild / resolvers += props.SonatypeSnapshots
ThisBuild / scalafixDependencies += "com.github.xuwei-k" %% "scalafix-rules" % "0.2.17"
ThisBuild / scalafixConfig := (
if (scalaVersion.value.startsWith("3"))
((ThisBuild / baseDirectory).value / ".scalafix-scala3.conf").some
else
((ThisBuild / baseDirectory).value / ".scalafix-scala2.conf").some
)
ThisBuild / scalafixScalaBinaryVersion := {
val log = sLog.value
val newVersion = if (scalaVersion.value.startsWith("3")) {
(ThisBuild / scalafixScalaBinaryVersion).value
} else {
CrossVersion.binaryScalaVersion(scalaVersion.value)
}
log.info(
s">> Change ThisBuild / scalafixScalaBinaryVersion from ${(ThisBuild / scalafixScalaBinaryVersion).value} to $newVersion"
)
newVersion
}
lazy val openai4s = (project in file("."))
.enablePlugins(DevOopsGitHubReleasePlugin)
.settings(
name := prefixedProjectName(""),
description := "openai4s - OpenAI Client for Scala",
libraryDependencies :=
libraryDependenciesPostProcess(isScala3(scalaVersion.value), libraryDependencies.value),
)
.settings(noPublish)
.settings(mavenCentralPublishSettings)
.aggregate(
coreJvm,
coreJs,
configJvm,
configJs,
http4sJvm,
http4sJs,
apiJvm,
apiJs,
)
lazy val core = module("core", crossProject(JVMPlatform, JSPlatform))
.settings(
libraryDependencies ++= List(
libs.cats,
libs.kittens(scalaVersion.value),
) ++
(
if (isScala3(scalaVersion.value))
libs.tests.hedgehogExtraScala3
else
List(libs.newtype) ++ libs.tests.hedgehogExtraScala2
) ++
libs.refined(scalaVersion.value) ++ libs.extras(scalaVersion.value) ++ libs.circeAll(
scalaVersion.value
)
)
lazy val coreJvm = core.jvm
lazy val coreJs = core.js.settings(jsSettingsForFuture)
lazy val config = module("config", crossProject(JVMPlatform, JSPlatform))
.settings(
libraryDependencies ++=
List(
libs.cats,
libs.kittens(scalaVersion.value),
libs.typeLevelCaseInsensitive,
libs.http4sCore,
) ++
(
if (isScala3(scalaVersion.value))
libs.tests.hedgehogExtraScala3
else
List(libs.newtype, libs.pureconfig) ++ libs.tests.hedgehogExtraScala2
) ++
libs.refined(scalaVersion.value) ++
libs.extras(scalaVersion.value) ++
libs.pureConfigAll
)
.dependsOn(core % props.IncludeTest)
lazy val configJvm = config.jvm
lazy val configJs = config.js.settings(jsSettingsForFuture)
lazy val http4s = module("http4s", crossProject(JVMPlatform, JSPlatform))
.settings(
libraryDependencies ++=
List(
libs.cats,
libs.logback,
libs.pureconfigCatsEffect3 % Test,
) ++
(if (isScala3(scalaVersion.value)) List.empty else List(libs.newtype)) ++
libs.refined(scalaVersion.value) ++
libs.circeAll(scalaVersion.value) ++
libs.http4s ++
libs.extras(scalaVersion.value)
)
.dependsOn(core, config)
lazy val http4sJvm = http4s.jvm
lazy val http4sJs = http4s.js.settings(jsSettingsForFuture)
lazy val api = module("api", crossProject(JVMPlatform, JSPlatform))
.settings(
libraryDependencies ++=
List(
libs.cats,
libs.logback,
libs.pureconfigCatsEffect3 % Test,
) ++
(
if (isScala3(scalaVersion.value))
libs.tests.hedgehogExtraScala3
else
List(libs.newtype) ++ libs.tests.hedgehogExtraScala2
) ++
libs.refined(scalaVersion.value) ++ libs.circeAll(scalaVersion.value)
)
.dependsOn(core % props.IncludeTest, config, http4s % props.IncludeTest)
lazy val apiJvm = api.jvm
lazy val apiJs = api.js.settings(jsSettingsForFuture)
lazy val props =
new {
val Org = "io.kevinlee"
val GitHubUsername = "kevin-lee"
val RepoName = "openai4s"
val Scala2Versions = List(
"2.13.12"
)
val Scala2Version = Scala2Versions.head
val Scala3Version = "3.3.1"
// val ProjectScalaVersion = "2.13.10"
// val ProjectScalaVersion = Scala2Version
val ProjectScalaVersion = Scala3Version
lazy val licenses = List(License.MIT)
val SonatypeCredentialHost = "s01.oss.sonatype.org"
val SonatypeRepository = s"https://$SonatypeCredentialHost/service/local"
val SonatypeSnapshots = "sonatype-snapshots" at s"https://$SonatypeCredentialHost/content/repositories/snapshots"
val removeDottyIncompatible: ModuleID => Boolean =
m =>
m.name == "ammonite" ||
m.name == "kind-projector" ||
m.name == "better-monadic-for" ||
m.name == "mdoc"
val CrossScalaVersions =
(Scala3Version :: Scala2Versions).distinct
val IncludeTest = "compile->compile;test->test"
val HedgehogVersion = "0.10.1"
val HedgehogExtraVersion = "0.7.0"
val CatsVersion = "2.10.0"
val CatsEffect2Version = "2.4.1"
val CatsEffect2LatestVersion = "2.5.5"
val CatsEffect3Version = "3.5.3"
val ExtrasVersion = "0.42.0"
val NewtypeVersion = "0.4.4"
val Refined4sVersion = "0.15.0"
val TypeLevelCaseInsensitiveVersion = "1.4.0"
val RefinedVersion = "0.10.1"
val RefinedLatestVersion = "0.11.0"
val KittensVersion = "3.0.0"
val KittensForScala3_1_Version = "3.0.0-M4"
val Http4sVersion = "0.22.15"
val Http4sLatestVersion = "0.23.23"
val PureConfigVersion = "0.17.4"
val CirceVersion = "0.14.3"
val CirceLatestVersion = "0.14.5"
val LogbackVersion = "1.4.11"
}
lazy val libs = new {
lazy val newtype = "io.estatico" %% "newtype" % props.NewtypeVersion
def refined4s(scalaVersion: String) =
if (isScala3(scalaVersion))
List(
"io.kevinlee" %% "refined4s-core" % props.Refined4sVersion,
"io.kevinlee" %% "refined4s-cats" % props.Refined4sVersion,
"io.kevinlee" %% "refined4s-circe" % props.Refined4sVersion,
"io.kevinlee" %% "refined4s-pureconfig" % props.Refined4sVersion,
"io.kevinlee" %% "refined4s-extras-render" % props.Refined4sVersion,
"io.kevinlee" %% "refined4s-refined-compat-scala3" % props.Refined4sVersion,
)
else
List("io.kevinlee" %% "refined4s-refined-compat-scala2" % props.Refined4sVersion)
def refined(scalaVersion: String): List[ModuleID] =
(if (isScala3(scalaVersion))
List.empty
else
List(
"eu.timepit" %% "refined" % props.RefinedVersion,
"eu.timepit" %% "refined-cats" % props.RefinedVersion,
// "eu.timepit" %% "refined-eval" % props.RefinedVersion,
"eu.timepit" %% "refined-pureconfig" % props.RefinedVersion,
)) ++ refined4s(scalaVersion)
def kittens(scalaVersion: String) = {
val version =
if (scalaVersion.startsWith("3.1")) props.KittensForScala3_1_Version
else
props.KittensVersion
"org.typelevel" %% "kittens" % version
}
lazy val cats = "org.typelevel" %% "cats-core" % props.CatsVersion
def extras(scalaVersion: String): List[ModuleID] = {
List(
"io.kevinlee" %% "extras-render" % props.ExtrasVersion,
"io.kevinlee" %% "extras-cats" % props.ExtrasVersion,
"io.kevinlee" %% "extras-circe" % props.ExtrasVersion,
"io.kevinlee" %% "extras-scala-io" % props.ExtrasVersion,
"io.kevinlee" %% "extras-hedgehog-ce3" % props.ExtrasVersion % Test,
"io.kevinlee" %% "extras-hedgehog-circe" % props.ExtrasVersion % Test,
"io.kevinlee" %% "extras-type-info" % props.ExtrasVersion,
"io.kevinlee" %% "extras-fs2-v3-text" % props.ExtrasVersion,
"io.kevinlee" %% "extras-testing-tools-cats" % props.ExtrasVersion % Test,
"io.kevinlee" %% "extras-testing-tools-effectie" % props.ExtrasVersion % Test,
) ++ (if (isScala3(scalaVersion)) List.empty
else
List(
"io.kevinlee" %% "extras-refinement" % props.ExtrasVersion,
"io.kevinlee" %% "extras-render-refined" % props.ExtrasVersion,
))
}
lazy val typeLevelCaseInsensitive = "org.typelevel" %% "case-insensitive" % props.TypeLevelCaseInsensitiveVersion
lazy val circeCore = "io.circe" %% "circe-core"
lazy val circeGeneric = "io.circe" %% "circe-generic"
lazy val circeGenericExtras = "io.circe" %% "circe-generic-extras"
lazy val circeParser = "io.circe" %% "circe-parser"
lazy val circeLiteral = "io.circe" %% "circe-literal"
lazy val circeRefined = "io.circe" %% "circe-refined"
def circeAll(scalaVersion: String): List[ModuleID] = {
val circeVersion = if (isScala3(scalaVersion)) props.CirceLatestVersion else props.CirceVersion
List(
circeCore % circeVersion,
circeGeneric % circeVersion,
circeParser % circeVersion % Test,
circeLiteral % circeVersion % Test,
) ++ (if (isScala3(scalaVersion)) List.empty
else
List(
circeGenericExtras % circeVersion,
circeRefined % circeVersion,
))
}
lazy val http4sCore = "org.http4s" %% "http4s-core" % props.Http4sLatestVersion
lazy val http4s = List(
http4sCore,
"org.http4s" %% "http4s-ember-client" % props.Http4sLatestVersion,
"org.http4s" %% "http4s-circe" % props.Http4sLatestVersion,
"org.http4s" %% "http4s-dsl" % props.Http4sLatestVersion,
)
lazy val pureConfigAll = List(
"com.github.pureconfig" %% "pureconfig-core" % props.PureConfigVersion,
"com.github.pureconfig" %% "pureconfig-http4s" % props.PureConfigVersion,
"com.github.pureconfig" %% "pureconfig-ip4s" % props.PureConfigVersion,
)
lazy val pureconfig = "com.github.pureconfig" %% "pureconfig" % props.PureConfigVersion
lazy val pureconfigCatsEffect3 =
"com.github.pureconfig" %% "pureconfig-cats-effect" % props.PureConfigVersion
lazy val logback = "ch.qos.logback" % "logback-classic" % props.LogbackVersion
lazy val tests = new {
lazy val hedgehogCore = "qa.hedgehog" %% "hedgehog-core" % props.HedgehogVersion % Test
lazy val hedgehogRunner = "qa.hedgehog" %% "hedgehog-runner" % props.HedgehogVersion % Test
lazy val hedgehogSbt = "qa.hedgehog" %% "hedgehog-sbt" % props.HedgehogVersion % Test
lazy val hedgehog: List[ModuleID] =
List(
hedgehogCore,
hedgehogRunner,
hedgehogSbt,
)
lazy val hedgehogExtraCore = "io.kevinlee" %% "hedgehog-extra-core" % props.HedgehogExtraVersion % Test
lazy val hedgehogExtraRefined = "io.kevinlee" %% "hedgehog-extra-refined" % props.HedgehogExtraVersion % Test
lazy val hedgehogExtraRefined4s = "io.kevinlee" %% "hedgehog-extra-refined4s" % props.HedgehogExtraVersion % Test
lazy val hedgehogExtraScala2 = List(
hedgehogExtraCore,
hedgehogExtraRefined,
)
lazy val hedgehogExtraScala3 = List(
hedgehogExtraCore,
hedgehogExtraRefined4s,
)
}
}
lazy val mavenCentralPublishSettings: SettingsDefinition = List(
/* Publish to Maven Central { */
sonatypeCredentialHost := props.SonatypeCredentialHost,
sonatypeRepository := props.SonatypeRepository,
/* } Publish to Maven Central */
)
// scalafmt: off
def prefixedProjectName(name: String) = s"${props.RepoName}${if (name.isEmpty) "" else s"-$name"}"
// scalafmt: on
def isScala3(scalaVersion: String): Boolean = scalaVersion.startsWith("3")
def libraryDependenciesPostProcess(
isDotty: Boolean,
libraries: Seq[ModuleID],
): Seq[ModuleID] =
if (isDotty)
libraries.filterNot(props.removeDottyIncompatible)
else
libraries
def module(projectName: String, crossProject: CrossProject.Builder): CrossProject = {
val prefixedName = prefixedProjectName(projectName)
crossProject
.in(file(s"modules/$prefixedName"))
.settings(
name := prefixedName,
fork := true,
semanticdbEnabled := true,
semanticdbVersion := scalafixSemanticdb.revision,
scalafixConfig := (
if (scalaVersion.value.startsWith("3"))
((ThisBuild / baseDirectory).value / ".scalafix-scala3.conf").some
else
((ThisBuild / baseDirectory).value / ".scalafix-scala2.conf").some
),
scalacOptions ++= (if (isScala3(scalaVersion.value)) List.empty else List("-Xsource:3")),
scalacOptions ~= (_.map {
case "UTF-8" => "utf8"
case s => s
}),
libraryDependencies ++= libs.tests.hedgehog,
wartremoverErrors ++= Warts.allBut(Wart.Any, Wart.Nothing, Wart.ImplicitConversion, Wart.ImplicitParameter),
Compile / console / scalacOptions :=
(console / scalacOptions)
.value
.filterNot(option => option.contains("wartremover") || option.contains("import")),
Test / console / scalacOptions :=
(console / scalacOptions)
.value
.filterNot(option => option.contains("wartremover") || option.contains("import")),
/* } WartRemover and scalacOptions */
licenses := props.licenses,
/* coverage { */
coverageHighlighting := (CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 10)) | Some((2, 11)) =>
false
case _ =>
true
}),
/* } coverage */
scalacOptions ++= (if (scalaVersion.value.startsWith("2.13")) List("-Ymacro-annotations") else List.empty),
)
.settings(mavenCentralPublishSettings)
}
lazy val jsSettingsForFuture: SettingsDefinition = List(
Test / fork := false,
Test / scalacOptions ++= (if (scalaVersion.value.startsWith("3")) List.empty
else List("-P:scalajs:nowarnGlobalExecutionContext")),
Test / compile / scalacOptions ++= (if (scalaVersion.value.startsWith("3")) List.empty
else List("-P:scalajs:nowarnGlobalExecutionContext")),
)