forked from fd4s/fs2-kafka
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sbt
304 lines (277 loc) · 9.88 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
import ReleaseTransformations._
val fs2Version = "1.0.4"
val kafkaVersion = "2.1.1"
lazy val `fs2-kafka` = project
.in(file("."))
.settings(
moduleName := "fs2-kafka",
name := moduleName.value,
dependencySettings,
publishSettings,
mimaSettings,
scalaSettings,
testSettings
)
lazy val docs = project
.in(file("docs"))
.settings(
moduleName := "fs2-kafka-docs",
name := moduleName.value,
noPublishSettings,
scalaSettings,
mdocSettings,
buildInfoSettings
)
.dependsOn(`fs2-kafka`)
.enablePlugins(BuildInfoPlugin, DocusaurusPlugin, MdocPlugin)
lazy val dependencySettings = Seq(
libraryDependencies ++= Seq(
"co.fs2" %% "fs2-core" % fs2Version,
"org.apache.kafka" % "kafka-clients" % kafkaVersion
),
libraryDependencies ++= Seq(
"org.scalatest" %% "scalatest" % "3.0.5",
"org.typelevel" %% "cats-testkit" % "1.6.0",
"org.scalacheck" %% "scalacheck" % "1.14.0",
"ch.qos.logback" % "logback-classic" % "1.2.3",
"io.github.embeddedkafka" %% "embedded-kafka" % "2.1.0",
"org.apache.kafka" %% "kafka" % kafkaVersion
).map(_ % Test)
)
lazy val mdocSettings = Seq(
mdoc := run.in(Compile).evaluated,
scalacOptions -= "-Xfatal-warnings",
crossScalaVersions := Seq(scalaVersion.value)
)
lazy val buildInfoSettings = Seq(
buildInfoPackage := "fs2.kafka.build",
buildInfoObject := "info",
buildInfoKeys := Seq[BuildInfoKey](
scalaVersion,
scalacOptions,
sourceDirectory,
latestVersion in ThisBuild,
moduleName in `fs2-kafka`,
organization in `fs2-kafka`,
crossScalaVersions in `fs2-kafka`,
BuildInfoKey("fs2Version" -> fs2Version),
BuildInfoKey("kafkaVersion" -> kafkaVersion)
)
)
lazy val metadataSettings = Seq(
organization := "com.ovoenergy",
organizationName := "OVO Energy Limited",
organizationHomepage := Some(url("https://ovoenergy.com"))
)
lazy val publishSettings =
metadataSettings ++ Seq(
publishMavenStyle := true,
publishArtifact in Test := false,
publishTo := sonatypePublishTo.value,
pomIncludeRepository := (_ => false),
homepage := Some(url("https://ovotech.github.io/fs2-kafka")),
licenses := List("Apache-2.0" -> url("https://www.apache.org/licenses/LICENSE-2.0.txt")),
startYear := Some(2018),
headerLicense := Some(
de.heikoseeberger.sbtheader.License.ALv2(
s"${startYear.value.get}-${java.time.Year.now}",
organizationName.value
)
),
developers := List(
Developer(
id = "vlovgr",
name = "Viktor Lövgren",
email = "[email protected]",
url = url("https://vlovgr.se")
)
),
scmInfo := Some(
ScmInfo(
url("https://github.com/ovotech/fs2-kafka"),
"scm:[email protected]:ovotech/fs2-kafka.git"
)
),
useGpg := true,
releaseCrossBuild := true,
releaseUseGlobalVersion := true,
releaseTagName := s"v${(version in ThisBuild).value}",
releasePublishArtifactsAction := PgpKeys.publishSigned.value,
releaseTagComment := s"Release version ${(version in ThisBuild).value}",
releaseCommitMessage := s"Set version to ${(version in ThisBuild).value}",
releaseProcess := Seq[ReleaseStep](
checkSnapshotDependencies,
inquireVersions,
runClean,
runTest,
setReleaseVersion,
setLatestVersion,
releaseStepTask(updateSiteVariables in ThisBuild),
releaseStepTask(addDateToReleaseNotes in ThisBuild),
commitReleaseVersion,
tagRelease,
publishArtifacts,
releaseStepCommand("sonatypeRelease"),
setNextVersion,
commitNextVersion,
pushChanges,
releaseStepCommand("docs/docusaurusPublishGhpages")
)
)
lazy val mimaSettings = Seq(
mimaPreviousArtifacts := {
if (publishArtifact.value)
binaryCompatibleVersions.value
.map(version => organization.value %% moduleName.value % version)
else
Set.empty
},
mimaBinaryIssueFilters ++= {
import com.typesafe.tools.mima.core._
// format: off
Seq(
ProblemFilters.exclude[ReversedMissingMethodProblem]("fs2.kafka.ProducerSettings.withDeliveryTimeout"),
ProblemFilters.exclude[DirectMissingMethodProblem]("fs2.kafka.ConsumerSettings#ConsumerSettingsImpl.apply"),
ProblemFilters.exclude[ReversedMissingMethodProblem]("fs2.kafka.ConsumerSettings.withMaxPrefetchBatches"),
ProblemFilters.exclude[ReversedMissingMethodProblem]("fs2.kafka.ConsumerSettings.maxPrefetchBatches"),
ProblemFilters.exclude[DirectMissingMethodProblem]("fs2.kafka.ConsumerSettings#ConsumerSettingsImpl.copy"),
ProblemFilters.exclude[DirectMissingMethodProblem]("fs2.kafka.ConsumerSettings#ConsumerSettingsImpl.this"),
ProblemFilters.exclude[ReversedMissingMethodProblem]("fs2.kafka.Headers.asJava"),
ProblemFilters.exclude[ReversedMissingMethodProblem]("fs2.kafka.Headers.withKey"),
ProblemFilters.exclude[ReversedMissingMethodProblem]("fs2.kafka.Headers.concat"),
ProblemFilters.exclude[ReversedMissingMethodProblem]("fs2.kafka.KafkaAdminClient.createTopic"),
ProblemFilters.exclude[ReversedMissingMethodProblem]("fs2.kafka.KafkaAdminClient.createTopics"),
ProblemFilters.exclude[ReversedMissingMethodProblem]("fs2.kafka.KafkaAdminClient.describeCluster"),
ProblemFilters.exclude[ReversedMissingMethodProblem]("fs2.kafka.KafkaConsumer.assignment"),
ProblemFilters.exclude[ReversedMissingMethodProblem]("fs2.kafka.KafkaConsumer.position"),
ProblemFilters.exclude[ReversedMissingMethodProblem]("fs2.kafka.KafkaConsumer.seekToBeginning"),
ProblemFilters.exclude[ReversedMissingMethodProblem]("fs2.kafka.KafkaConsumer.seekToEnd")
)
// format: on
}
)
lazy val noPublishSettings =
metadataSettings ++ Seq(
skip in publish := true,
publishArtifact := false
)
lazy val scalaSettings = Seq(
scalaVersion := "2.12.8",
crossScalaVersions := Seq("2.11.12", scalaVersion.value),
scalacOptions ++= Seq(
"-deprecation",
"-encoding",
"UTF-8",
"-feature",
"-language:existentials",
"-language:higherKinds",
"-language:implicitConversions",
"-unchecked",
"-Xfatal-warnings",
"-Xlint",
"-Yno-adapted-args",
"-Ywarn-dead-code",
"-Ywarn-numeric-widen",
"-Ywarn-value-discard",
"-Xfuture",
"-Ywarn-unused",
"-Ypartial-unification"
),
scalacOptions in (Compile, console) --= Seq("-Xlint", "-Ywarn-unused"),
scalacOptions in (Test, console) := (scalacOptions in (Compile, console)).value
)
lazy val testSettings = Seq(
logBuffered in Test := false,
parallelExecution in Test := false,
testOptions in Test += Tests.Argument("-oDF")
)
def minorVersion(version: String): String = {
val (major, minor) =
CrossVersion.partialVersion(version).get
s"$major.$minor"
}
val validateDocs = taskKey[Unit]("Validate documentation")
validateDocs in ThisBuild := (run in (docs, Compile)).toTask(" ").value
val releaseNotesFile = taskKey[File]("Release notes for current version")
releaseNotesFile in ThisBuild := {
val currentVersion = (version in ThisBuild).value
file("notes") / s"$currentVersion.markdown"
}
val updateSiteVariables = taskKey[Unit]("Update site variables")
updateSiteVariables in ThisBuild := {
val file = (baseDirectory in `fs2-kafka`).value / "website" / "siteConfig.js"
val lines = IO.read(file).trim.split('\n').toVector
val scalaMinorVersion = minorVersion((scalaVersion in `fs2-kafka`).value)
val latestVersionString = (latestVersion in ThisBuild).value.toString
val organizationString = (organization in `fs2-kafka`).value
val moduleNameString = (moduleName in `fs2-kafka`).value
val scalaPublishVersions = {
val minorVersions = (crossScalaVersions in `fs2-kafka`).value.map(minorVersion)
if (minorVersions.size <= 2) minorVersions.mkString(" and ")
else minorVersions.init.mkString(", ") ++ " and " ++ minorVersions.last
}
val lineIndex = lines.indexWhere(_.trim.startsWith("const buildInfo"))
val newLine =
s"const buildInfo = { organization: '$organizationString', moduleName: '$moduleNameString', latestVersion: '$latestVersionString', scalaMinorVersion: '$scalaMinorVersion', scalaPublishVersions: '$scalaPublishVersions' };"
val newLines = lines.updated(lineIndex, newLine)
val newFileContents = newLines.mkString("", "\n", "\n")
IO.write(file, newFileContents)
sbtrelease.Vcs.detect((baseDirectory in `fs2-kafka`).value).foreach { vcs =>
vcs.add(file.getAbsolutePath).!
vcs
.commit(
s"Update site variables for v${(version in ThisBuild).value}",
sign = true,
signOff = false
)
.!
}
}
val ensureReleaseNotesExists = taskKey[Unit]("Ensure release notes exists")
ensureReleaseNotesExists in ThisBuild := {
val currentVersion = (version in ThisBuild).value
val notes = releaseNotesFile.value
if (!notes.isFile) {
throw new IllegalStateException(
s"no release notes found for version [$currentVersion] at [$notes]."
)
}
}
val addDateToReleaseNotes = taskKey[Unit]("Add current date to release notes")
addDateToReleaseNotes in ThisBuild := {
ensureReleaseNotesExists.value
val dateString = {
val formatter = java.time.format.DateTimeFormatter.ofPattern("yyyy-MM-dd")
val now = java.time.ZonedDateTime.now()
now.format(formatter)
}
val file = releaseNotesFile.value
val newContents = IO.read(file).trim + s"\n\nReleased on $dateString.\n"
IO.write(file, newContents)
sbtrelease.Vcs.detect((baseDirectory in `fs2-kafka`).value).foreach { vcs =>
vcs.add(file.getAbsolutePath).!
vcs
.commit(
s"Add release date for v${(version in ThisBuild).value}",
sign = true,
signOff = false
)
.!
}
}
def addCommandsAlias(name: String, values: List[String]) =
addCommandAlias(name, values.mkString(";", ";", ""))
addCommandsAlias(
"validate",
List(
"clean",
"coverage",
"test",
"coverageReport",
"mimaReportBinaryIssues",
"scalafmtCheck",
"scalafmtSbtCheck",
"headerCheck",
"doc"
)
)