forked from ITV/scala-pact
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sbt
428 lines (394 loc) · 15.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
lazy val compilerOptions212 = Seq(
"-Xfuture", // Turn on future language features.
"-Xlint:by-name-right-associative", // By-name parameter of right associative operator.
"-Xlint:unsound-match", // Pattern match may not be typesafe.
"-Yno-adapted-args", // Do not adapt an argument list (either by inserting () or creating a tuple) to match the receiver.
"-Ywarn-dead-code", // Warn when dead code is identified.
"-Ywarn-extra-implicit", // Warn when more than one implicit parameter section is defined.
"-Ywarn-infer-any", // Warn when a type argument is inferred to be `Any`.
"-Ywarn-nullary-override", // Warn when non-nullary `def f()' overrides nullary `def f'.
"-Ywarn-nullary-unit", // Warn when nullary methods return Unit.
"-Ywarn-numeric-widen", // Warn when numerics are widened.
"-Ywarn-unused:implicits", // Warn if an implicit parameter is unused.
"-Ywarn-unused:imports", // Warn if an import selector is not referenced.
"-Ywarn-unused:locals", // Warn if a local definition is unused.
"-Ywarn-unused:params", // Warn if a value parameter is unused.
"-Ywarn-unused:patvars", // Warn if a variable bound in a pattern is unused.
"-Ywarn-unused:privates", // Warn if a private member is unused.
"-Ywarn-value-discard", // Warn when non-Unit expression results are unused.
"-Ypartial-unification" // Enable partial unification in type constructor inference
)
lazy val compilerOptions213 = Seq(
"-Xlint:adapted-args", // Warn if an argument list is modified to match the receiver.
"-Xlint:inaccessible", // Warn about inaccessible types in method signatures.
"-Xlint:infer-any", // Warn when a type argument is inferred to be Any.
"-Xlint:nullary-unit", // Warn when nullary methods return Unit.
"-Xlint:unused", // Enable -Ywarn-unused:imports,privates,locals,implicits.
"-Wdead-code", // Warn when dead code is identified.
"-Wextra-implicit", // Warn when more than one implicit parameter section is defined.
"-Wnumeric-widen", // Warn when numerics are widened.
"-Wunused:patvars", // Warn if a variable bound in a pattern is unused.
"-Wvalue-discard" // Warn when non-Unit expression results are unused.
)
lazy val compilerOptionsAll = Seq(
"-deprecation", // Emit warning and location for usages of deprecated APIs.
"-encoding",
"utf-8", // Specify character encoding used by source files.
"-explaintypes", // Explain type errors in more detail.
"-feature", // Emit warning and location for usages of features that should be imported explicitly.
"-language:existentials", // Existential types (besides wildcard types) can be written and inferred
"-language:experimental.macros", // Allow macro definition (besides implementation and application)
"-language:higherKinds", // Allow higher-kinded types
"-unchecked", // Enable additional warnings where generated code depends on assumptions.
"-Xcheckinit", // Wrap field accessors to throw an exception on uninitialized access.
"-Xfatal-warnings", // Fail the compilation if there are any warnings.
"-Xlint:adapted-args", // Warn if an argument list is modified to match the receiver.
"-Xlint:constant", // Evaluation of a constant arithmetic expression results in an error.
"-Xlint:delayedinit-select", // Selecting member of DelayedInit.
"-Xlint:doc-detached", // A Scaladoc comment appears to be detached from its element.
"-Xlint:inaccessible", // Warn about inaccessible types in method signatures.
"-Xlint:infer-any", // Warn when a type argument is inferred to be `Any`.
"-Xlint:missing-interpolator", // A string literal appears to be missing an interpolator id.
"-Xlint:nullary-unit", // Warn when nullary methods return Unit.
"-Xlint:option-implicit", // Option.apply used implicit view.
"-Xlint:package-object-classes", // Class or object defined in package object.
"-Xlint:poly-implicit-overload", // Parameterized overloaded implicit methods are not visible as view bounds.
"-Xlint:private-shadow", // A private field (or class parameter) shadows a superclass field.
"-Xlint:stars-align", // Pattern sequence wildcard must align with sequence component.
"-Xlint:type-parameter-shadow" // A local type parameter shadows a type already in scope.
)
def compilerOptionsVersion(scalaVersion: String) =
compilerOptionsAll ++ (CrossVersion.partialVersion(scalaVersion) match {
case Some((2L, 12L)) => compilerOptions212
case Some((2L, 13L)) => compilerOptions213
case _ => Nil
})
lazy val scalaVersion212: String = "2.12.12"
lazy val scalaVersion213: String = "2.13.4"
lazy val supportedScalaVersions = List(scalaVersion212, scalaVersion213)
ThisBuild / scalaVersion := scalaVersion212
lazy val commonSettings = Seq(
organization := "com.itv",
crossScalaVersions := supportedScalaVersions,
scalacOptions ++= compilerOptionsVersion(scalaVersion.value),
libraryDependencies ++= Seq(
"org.scalatest" %% "scalatest" % "3.0.8" % "test"
),
wartremoverWarnings in (Compile, compile) ++= Warts.allBut(
Wart.Any,
Wart.Overloading,
Wart.FinalCaseClass,
Wart.Nothing,
Wart.ImplicitParameter,
Wart.NonUnitStatements,
Wart.Throw,
Wart.Equals,
Wart.Recursion,
Wart.LeakingSealed,
Wart.Null,
Wart.Var,
Wart.StringPlusAny,
Wart.PlatformDefault,
Wart.ListUnapply,
Wart.GlobalExecutionContext
),
parallelExecution in Test := false,
// javaOptions in Test ++= Seq(
// "-XX:+UnlockCommercialFeatures", "-XX:+FlightRecorder"
// ),
test in assembly := {}
)
lazy val scala212OnlySettings = Seq(
crossScalaVersions := Seq(scalaVersion212)
)
lazy val mockSettings = Seq(
libraryDependencies += "org.scalamock" %% "scalamock" % "4.0.0" % Test
)
lazy val publishSettings = Seq(
publishTo := {
val nexus = "https://oss.sonatype.org/"
if (isSnapshot.value)
Some("snapshots" at nexus + "content/repositories/snapshots")
else
Some("releases" at nexus + "service/local/staging/deploy/maven2")
},
publishTo := sonatypePublishToBundle.value,
publishMavenStyle := true,
publishArtifact in Test := false,
pomIncludeRepository := { _ =>
false
},
pomExtra :=
<url>https://github.com/ITV/scala-pact</url>
<licenses>
<license>
<name>ITV-OSS</name>
<url>http://itv.com/itv-oss-licence-v1.0</url>
<distribution>repo</distribution>
</license>
</licenses>
<developers>
<developer>
<id>davesmith00000</id>
<name>David Smith</name>
<organization>ITV</organization>
<organizationUrl>http://www.itv.com</organizationUrl>
</developer>
</developers>
)
lazy val shared =
(project in file("scalapact-shared"))
.enablePlugins(BuildInfoPlugin)
.settings(
buildInfoKeys := Seq[BuildInfoKey](version),
buildInfoPackage := "com.itv.scalapact.shared"
)
.settings(commonSettings: _*)
.settings(publishSettings: _*)
.settings(
name := "scalapact-shared",
libraryDependencies ++= Seq("org.scala-lang.modules" %% "scala-xml" % "1.2.0")
)
lazy val core =
(project in file("scalapact-core"))
.settings(commonSettings: _*)
.settings(publishSettings: _*)
.settings(
name := "scalapact-core"
)
.dependsOn(shared)
lazy val http4s021 =
(project in file("scalapact-http4s-0-21"))
.settings(commonSettings: _*)
.settings(publishSettings: _*)
.settings(
name := "scalapact-http4s-0-21",
libraryDependencies ++= Seq(
"org.http4s" %% "http4s-blaze-server" % "0.21.7" exclude("org.scala-lang.modules", "scala-xml"),
"org.http4s" %% "http4s-blaze-client" % "0.21.7" exclude("org.scala-lang.modules", "scala-xml"),
"org.http4s" %% "http4s-dsl" % "0.21.7",
"com.github.tomakehurst" % "wiremock" % "2.25.1" % "test"
)
)
.dependsOn(shared)
lazy val testShared =
(project in file("scalapact-test-shared"))
.settings(commonSettings: _*)
.settings(
name := "scalapact-test-shared",
skip in publish := true
)
.dependsOn(shared)
lazy val argonaut62 =
(project in file("scalapact-argonaut-6-2"))
.settings(commonSettings: _*)
.settings(publishSettings: _*)
.settings(
name := "scalapact-argonaut-6-2",
libraryDependencies ++= Seq(
"io.argonaut" %% "argonaut" % "6.2.5"
)
)
.dependsOn(shared)
.dependsOn(testShared % "test->compile")
lazy val circe13 =
(project in file("scalapact-circe-0-13"))
.settings(commonSettings: _*)
.settings(publishSettings: _*)
.settings(
name := "scalapact-circe-0-13",
libraryDependencies ++= Seq(
"io.circe" %% "circe-core",
"io.circe" %% "circe-generic",
"io.circe" %% "circe-parser"
).map(_ % "0.13.0")
)
.dependsOn(shared)
.dependsOn(testShared % "test->compile")
lazy val pluginShared =
(project in file("sbt-scalapact-shared"))
.settings(commonSettings: _*)
.settings(publishSettings: _*)
.settings(
name := "sbt-scalapact-shared"
)
.dependsOn(core)
.settings(scala212OnlySettings)
lazy val plugin =
(project in file("sbt-scalapact"))
.settings(commonSettings: _*)
.settings(publishSettings: _*)
.settings(
name := "sbt-scalapact",
sbtPlugin := true,
)
.dependsOn(pluginShared)
.dependsOn(circe13)
.dependsOn(http4s021)
.settings(scala212OnlySettings)
lazy val pluginNoDeps =
(project in file("sbt-scalapact-nodeps"))
.settings(commonSettings: _*)
.settings(publishSettings: _*)
.settings(
name := "sbt-scalapact-nodeps",
sbtPlugin := true,
)
.dependsOn(pluginShared)
.dependsOn(circe13 % "provided")
.dependsOn(http4s021 % "provided")
.settings(scala212OnlySettings)
lazy val framework =
(project in file("scalapact-scalatest"))
.settings(commonSettings: _*)
.settings(publishSettings: _*)
.settings(
name := "scalapact-scalatest",
mappings in (Compile, packageBin) ~= {
_.filterNot { case (_, fileName) => fileName == "logback.xml" || fileName == "log4j.properties" }
}
)
.dependsOn(core)
lazy val frameworkWithDeps =
(project in file("scalapact-scalatest-suite"))
.settings(commonSettings: _*)
.settings(publishSettings: _*)
.settings(
name := "scalapact-scalatest-suite",
mappings in (Compile, packageBin) ~= {
_.filterNot { case (_, fileName) => fileName == "logback.xml" || fileName == "log4j.properties" }
}
)
.dependsOn(framework)
.dependsOn(circe13)
.dependsOn(http4s021)
lazy val standalone =
(project in file("scalapact-standalone-stubber"))
.settings(commonSettings: _*)
.settings(
name := "scalapact-standalone-stubber",
publish := {},
assemblyJarName in assembly := "pactstubber.jar",
libraryDependencies ++= Seq(
"ch.qos.logback" % "logback-classic" % "1.2.3"
),
skip in publish := true
)
.dependsOn(core)
.dependsOn(circe13)
.dependsOn(http4s021)
lazy val pactSpec =
(project in file("pact-spec-tests"))
.settings(commonSettings: _*)
.settings(
name := "pact-spec-tests",
skip in publish := true
)
.settings(scala212OnlySettings)
.dependsOn(core)
.dependsOn(argonaut62)
lazy val testsWithDeps =
(project in file("tests-with-deps"))
.settings(commonSettings: _*)
.settings(
libraryDependencies ++= Seq(
"org.scalaj" %% "scalaj-http" % "2.4.2" % "test",
"org.json4s" %% "json4s-native" % "3.6.9" % "test",
"com.github.tomakehurst" % "wiremock" % "1.56" % "test",
"fr.hmil" %% "roshttp" % "2.1.0" % "test",
"io.argonaut" %% "argonaut" % "6.2.5"
),
skip in publish := true
)
.settings(scala212OnlySettings)
.dependsOn(framework)
.dependsOn(circe13)
.dependsOn(http4s021)
lazy val docs =
(project in file("scalapact-docs"))
.settings(commonSettings: _*)
.enablePlugins(ParadoxPlugin)
.enablePlugins(ParadoxSitePlugin)
.enablePlugins(GhpagesPlugin)
.settings(
paradoxTheme := Some(builtinParadoxTheme("generic")),
name := "scalapact-docs",
git.remoteRepo := "[email protected]:ITV/scala-pact.git",
sourceDirectory in Paradox := sourceDirectory.value / "main" / "paradox",
skip in publish := true
)
.settings(scala212OnlySettings)
lazy val scalaPactProject =
(project in file("."))
.settings(commonSettings: _*)
.settings(
skip in publish := true,
crossScalaVersions := Nil
)
.aggregate(shared, core, pluginShared, plugin, pluginNoDeps, framework, testShared)
.aggregate(http4s021)
.aggregate(argonaut62, circe13)
.aggregate(standalone, frameworkWithDeps)
.aggregate(docs)
.aggregate(pactSpec, testsWithDeps)
import ReleaseTransformations._
import sbtrelease.Utilities._
import sbtrelease.Vcs
import scala.sys.process.ProcessLogger
val readmeFileKey = settingKey[File]("The location of the readme")
readmeFileKey := baseDirectory.value / "README.md"
lazy val updateVersionsInReadme: ReleaseStep = { st: State =>
st.get(ReleaseKeys.versions).flatMap { case (newVersion, _) =>
val readmeFile = st.extract.get(readmeFileKey).getCanonicalFile
val readmeLines = IO.readLines(readmeFile)
val versionPrefix = "## Latest version is "
val currentVersion = readmeLines.collectFirst { case s if s.startsWith(versionPrefix) => s.replace(versionPrefix, "").dropWhile(_.isWhitespace)}
currentVersion.map { cv =>
IO.writeLines(readmeFile, readmeLines.map(_.replaceAll(cv, newVersion)))
}
}.getOrElse(())
st
}
lazy val commitReadMeVersionBump: ReleaseStep = { st: State =>
def vcs(st: State): Vcs = {
st.extract.get(releaseVcs).getOrElse(sys.error("Aborting release. Working directory is not a repository of a recognized VCS."))
}
val commitMessage: TaskKey[String] = releaseNextCommitMessage
val log = new ProcessLogger {
override def err(s: => String): Unit = st.log.info(s)
override def out(s: => String): Unit = st.log.info(s)
override def buffer[T](f: => T): T = st.log.buffer(f)
}
val readmeFile = st.extract.get(readmeFileKey).getCanonicalFile
val base = vcs(st).baseDir.getCanonicalFile
val sign = st.extract.get(releaseVcsSign)
val signOff = st.extract.get(releaseVcsSignOff)
val relativePathToReadme = IO.relativize(base, readmeFile).getOrElse("Readme file [%s] is outside of this VCS repository with base directory [%s]!" format(readmeFile, base))
vcs(st).add(relativePathToReadme) !! log
val status = vcs(st).status.!!.trim
val newState = if (status.nonEmpty) {
val (state, msg) = st.extract.runTask(commitMessage, st)
vcs(state).commit(msg, sign, signOff) ! log
state
} else {
st
}
newState
}
releaseCrossBuild := true // true if you cross-build the project for multiple Scala versions
releaseProcess := Seq[ReleaseStep](
checkSnapshotDependencies,
inquireVersions,
runClean,
runTest,
updateVersionsInReadme,
commitReadMeVersionBump,
setReleaseVersion,
commitReleaseVersion,
tagRelease,
releaseStepCommandAndRemaining("+publishSigned"),
releaseStepCommand("sonatypeBundleRelease"),
setNextVersion,
commitNextVersion,
pushChanges
)