-
Notifications
You must be signed in to change notification settings - Fork 4
/
build.sbt
272 lines (233 loc) · 7.87 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
// === Dependency Versions ===
val javaVersion = "21"
val latestKotlinVersion = "2.0.0"
val latestScalaVersion = "3.4.2"
val catsCore = "org.typelevel" %% "cats-core" % "2.10.0"
val circeCore = "io.circe" %% "circe-core" % "0.14.7"
val circeParser = "io.circe" %% "circe-parser" % "0.14.7"
val gson = "com.google.code.gson" % "gson" % "2.11.0"
val playJson = "org.playframework" %% "play-json" % "3.0.3"
val zio = "dev.zio" %% "zio" % "2.1.1"
val jUnit = "org.junit.jupiter" % "junit-jupiter" % "5.10.2" % Test
val jUnitInterface = "net.aichler" % "jupiter-interface" % "0.11.1" % Test
val mUnit = "org.scalameta" %% "munit" % "1.0.0" % Test
val mUnitScalaCheck = "org.scalameta" %% "munit-scalacheck" % "1.0.0" % Test
val zioTest = "dev.zio" %% "zio-test" % "2.1.1" % Test
val zioTestSBT = "dev.zio" %% "zio-test-sbt" % "2.1.1" % Test
// === Settings ===
import java.time.Year
Global / onChangedBuildSource := ReloadOnSourceChanges
val commonSettings = Seq(
resolvers += Resolver.jcenterRepo
)
val mdocSettings = Seq(
(publish / skip) := true,
mdocVariables := Map(
"VERSION" -> version.value,
"JAVA_VERSION" -> javaVersion,
"SCALA_VERSION" -> latestScalaVersion,
"KOTLIN_VERSION" -> latestKotlinVersion,
"COPYRIGHT_YEAR" -> Year.now.toString
),
mdocIn := file("docs"),
mdocOut := file(".")
)
val javaSettings: Seq[Setting[?]] = commonSettings ++ Seq(
crossPaths := false, // Do not append Scala versions to the generated artifacts
autoScalaLibrary := false, // Exclude Scala related libraries
javacOptions ++= Seq("-source", javaVersion),
libraryDependencies ++= Seq(
jUnit,
jUnitInterface
),
(Test / classLoaderLayeringStrategy) := ClassLoaderLayeringStrategy.Flat,
testOptions += Tests.Argument(jupiterTestFramework, "-q", "-v")
)
val scalaSettings: Seq[Setting[?]] = {
commonSettings ++ Seq(
scalaVersion := latestScalaVersion,
javacOptions ++= Seq("-source", javaVersion),
autoAPIMappings := true,
exportJars := true,
apiMappings ++= {
val classpath = (Compile / fullClasspath).value
def findJar(name: String): File = {
val regex = ("/" + name + "[^/]*.jar$").r
classpath.find { jar => regex.findFirstIn(jar.data.toString).nonEmpty }.get.data
}
Map(
findJar("scala3-library") -> url(s"https://scala-lang.org/api/$latestScalaVersion/")
)
},
testFrameworks += new TestFramework("munit.Framework"),
libraryDependencies ++= Seq(
mUnit,
mUnitScalaCheck
)
)
}
lazy val kotlinSettings: Seq[Setting[?]] = javaSettings ++ Seq(
kotlinLib("stdlib"),
kotlinVersion := latestKotlinVersion,
// Delegate doc generation to Gradle and Dokka
(Compile / doc) := {
import sys.process.*
Process(Seq("./gradlew", "dokkaJavadoc"), baseDirectory.value).!
target.value / "api"
},
// Include Kotlin files in sources
(Compile / packageConfiguration) := {
val old = (Compile / packageSrc / packageConfiguration).value
val newSources = (Compile / sourceDirectories).value.flatMap(f => (f ** "*.kt").get)
new Package.Configuration(
old.sources ++ newSources.map(f => f -> f.getName),
old.jar,
old.options
)
},
libraryDependencies ++= Seq(
jUnit,
jUnitInterface
),
testOptions += Tests.Argument(jupiterTestFramework, "-q", "-v")
)
// === Modules ===
lazy val e = project
.in(file("."))
.aggregate(`e-scala`, `e-kotlin`, `e-java`, `e-circe`, `e-play-json`, `e-gson`, `e-zio`)
lazy val `e-docs` = project
.in(file("e-docs"))
.dependsOn(`e-scala`, `e-kotlin`, `e-java`, `e-circe`, `e-play-json`, `e-gson`, `e-zio`)
.enablePlugins(MdocPlugin)
.settings(scalaSettings)
.settings(mdocSettings)
lazy val `e-scala` = project
.in(file("e-scala"))
.settings(scalaSettings)
lazy val `e-kotlin` = project
.in(file("e-kotlin"))
.settings(kotlinSettings)
.enablePlugins(KotlinPlugin)
lazy val `e-java` = project
.in(file("e-java"))
.settings(javaSettings)
lazy val `e-circe` = project
.in(file("e-circe"))
.dependsOn(`e-scala` % "compile->compile;test->test")
.settings(scalaSettings)
.settings(
libraryDependencies ++= Seq(
circeCore,
circeParser
)
)
lazy val `e-play-json` = project
.in(file("e-play-json"))
.dependsOn(`e-scala` % "compile->compile;test->test")
.settings(scalaSettings)
.settings(
libraryDependencies ++= Seq(
catsCore,
playJson
)
)
lazy val `e-zio` = project
.in(file("e-zio"))
.dependsOn(`e-scala` % "compile->compile;test->test")
.settings(scalaSettings)
.settings(
libraryDependencies ++= Seq(
zio,
zioTest,
zioTestSBT
),
testFrameworks += new TestFramework("zio.test.sbt.ZTestFramework")
)
lazy val `e-gson` = project
.in(file("e-gson"))
.dependsOn(`e-java` % "compile->compile;test->test")
.settings(javaSettings)
.settings(
libraryDependencies ++= Seq(
gson
)
)
// === Project Metadata ===
ThisBuild / description := "A zero-dependency micro library to deal with errors"
ThisBuild / homepage := Some(url("https://github.com/makiftutuncu/e"))
ThisBuild / startYear := Some(2019)
ThisBuild / licenses := Seq("MIT" -> url("https://opensource.org/licenses/MIT"))
ThisBuild / organization := "dev.akif"
ThisBuild / organizationName := "Mehmet Akif Tütüncü"
ThisBuild / organizationHomepage := Some(url("https://akif.dev"))
ThisBuild / developers := List(
Developer("makiftutuncu", "Mehmet Akif Tütüncü", "[email protected]", url("https://akif.dev"))
)
ThisBuild / scmInfo := Some(ScmInfo(url("https://github.com/makiftutuncu/e"), "[email protected]:makiftutuncu/e.git"))
ThisBuild / versionScheme := Some("early-semver")
// === Release Settings ===
import sbtrelease.ReleasePlugin.autoImport.ReleaseTransformations.*
val sonatypeUser = sys.env.getOrElse("SONATYPE_USER", "")
val sonatypePass = sys.env.getOrElse("SONATYPE_PASS", "")
ThisBuild / credentials ++= Seq(
Credentials(
"Sonatype Nexus Repository Manager",
"oss.sonatype.org",
sonatypeUser,
sonatypePass
),
Credentials(
"GnuPG Key ID",
"gpg",
"3D5A9AE9F71508A0D85E78DF877A4F41752BB3B5",
"ignored"
)
)
ThisBuild / pomIncludeRepository := { _ => false }
ThisBuild / publishMavenStyle := true
ThisBuild / publishTo := {
Some(
if (isSnapshot.value) "snapshots" at "https://oss.sonatype.org/content/repositories/snapshots"
else "releases" at "https://oss.sonatype.org/service/local/staging/deploy/maven2"
)
}
Compile / packageBin / publishArtifact := true
Compile / packageSrc / publishArtifact := true
Compile / packageDoc / publishArtifact := true
val checkPublishCredentials = ReleaseStep { state =>
if (sonatypeUser.isEmpty || sonatypePass.isEmpty) {
throw new Exception(
"Sonatype credentials are missing! Make sure to provide SONATYPE_USER and SONATYPE_PASS environment variables."
)
}
state
}
val runMDoc = ReleaseStep(
releaseStepCommand("e-docs/mdoc") andThen { st =>
import sys.process.*
Process(Seq("git", "add", "-A"), st.baseDir).!
st
}
)
usePgpKeyHex("3D5A9AE9F71508A0D85E78DF877A4F41752BB3B5")
releaseProcess := Seq[ReleaseStep](
checkSnapshotDependencies,
checkPublishCredentials,
inquireVersions,
runClean,
runTest,
setReleaseVersion,
runMDoc,
commitReleaseVersion,
tagRelease,
releaseStepCommandAndRemaining("e-scala/publishSigned"),
releaseStepCommandAndRemaining("e-java/publishSigned"),
releaseStepCommandAndRemaining("e-kotlin/publishSigned"),
releaseStepCommandAndRemaining("e-circe/publishSigned"),
releaseStepCommandAndRemaining("e-play-json/publishSigned"),
releaseStepCommandAndRemaining("e-gson/publishSigned"),
releaseStepCommandAndRemaining("e-zio/publishSigned"),
setNextVersion,
commitNextVersion,
pushChanges
)