This repository has been archived by the owner on Apr 10, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
build.sbt
279 lines (249 loc) · 10.4 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
import bintray.Keys._
val PlayVersion = "2.4.3"
val ScalaVersion = "2.11.7"
// This is the API project, it gets added to the runtime dependencies of any
// project using play-swagger
lazy val api = (project in file("api"))
.settings(common: _*)
.settings(
name := "play-swagger-api",
libraryDependencies ++= Seq(
"com.fasterxml.jackson.core" % "jackson-databind" % "2.4.4",
"com.fasterxml.jackson.dataformat" % "jackson-dataformat-yaml" % "2.4.4",
"com.fasterxml.jackson.module" %% "jackson-module-scala" % "2.6.1",
"com.fasterxml.jackson.dataformat" % "jackson-dataformat-csv" % "2.6.4",
"joda-time" % "joda-time" % "2.9.1",
"com.typesafe.play" %% "play" % PlayVersion % Provided,
"com.typesafe.play" %% "play-java-ws" % PlayVersion,
"org.scalacheck" %% "scalacheck" % "1.12.4" % "test",
"org.specs2" %% "specs2-scalacheck" % "3.6" % "test",
"me.jeffmay" %% "play-json-tests" % "1.3.0" % "test"
),
scalaVersion := "2.10.5",
crossScalaVersions := Seq(scalaVersion.value, ScalaVersion),
resolvers ++= Seq(
"jeffmay" at "https://dl.bintray.com/jeffmay/maven"
)
)
lazy val swaggerModel = (project in file("swagger-model"))
.enablePlugins(BuildInfoPlugin)
.settings(common: _*)
.settings(
name := "swagger-model",
scalaVersion := "2.10.5",
sbtPlugin := false,
buildInfoKeys := Seq[BuildInfoKey](name, version, scalaVersion, sbtVersion),
buildInfoPackage := "de.zalando",
libraryDependencies ++= Seq(
"com.fasterxml.jackson.core" % "jackson-databind" % "2.4.4",
"com.fasterxml.jackson.dataformat" % "jackson-dataformat-yaml" % "2.4.4",
"com.fasterxml.jackson.module" %% "jackson-module-scala" % "2.6.1",
"me.andrz.jackson" % "jackson-json-reference-core" % "0.2.1",
"org.scalatest" %% "scalatest" % "2.2.6" % "test"
)
)
lazy val apiFirstCore = (project in file("api-first-core"))
.enablePlugins(BuildInfoPlugin)
.settings(common: _*)
.settings(
name := "api-first-core",
scalaVersion := "2.10.5",
libraryDependencies ++= Seq(
"org.scala-lang" % "scala-compiler" % scalaVersion.value,
"org.scala-lang" % "scala-library" % scalaVersion.value,
"org.scala-lang" % "scala-reflect" % scalaVersion.value,
"org.scalatest" %% "scalatest" % "2.2.3" % "test",
"org.scalacheck" %% "scalacheck" % "1.12.5" % "test"
)
)
.dependsOn(api)
lazy val swaggerParser = (project in file("swagger-parser"))
.enablePlugins(BuildInfoPlugin)
.settings(common: _*)
.settings(
name := "swagger-parser",
scalaVersion := "2.10.5",
sbtPlugin := false,
buildInfoKeys := Seq[BuildInfoKey](name, version, scalaVersion, sbtVersion),
buildInfoPackage := "de.zalando",
libraryDependencies ++= Seq(
"com.fasterxml.jackson.core" % "jackson-databind" % "2.4.4",
"com.fasterxml.jackson.dataformat" % "jackson-dataformat-yaml" % "2.4.4",
"com.fasterxml.jackson.module" %% "jackson-module-scala" % "2.6.1",
"me.andrz.jackson" % "jackson-json-reference-core" % "0.2.1",
"org.scalatest" %% "scalatest" % "2.2.6" % "test"
)
)
.dependsOn(swaggerModel, apiFirstCore)
lazy val playScalaGenerator = (project in file("play-scala-generator"))
.enablePlugins(BuildInfoPlugin)
.settings(common: _*)
.settings(
name := "play-scala-generator",
scalaVersion := "2.10.5",
sbtPlugin := false,
buildInfoKeys := Seq[BuildInfoKey](name, version, scalaVersion, sbtVersion),
buildInfoPackage := "de.zalando",
libraryDependencies ++= Seq(
"com.typesafe.play" %% "routes-compiler" % PlayVersion % Provided,
"com.typesafe.play" %% "play" % PlayVersion % Provided,
"org.scala-lang" % "scala-compiler" % scalaVersion.value,
"org.scala-lang" % "scala-library" % scalaVersion.value,
"org.scala-lang" % "scala-reflect" % scalaVersion.value,
"org.scalatest" %% "scalatest" % "2.2.6" % "test",
"org.scalacheck" %% "scalacheck" % "1.12.5" % "test",
"de.zalando" %% "beard" % "0.0.6"
)
).dependsOn(apiFirstCore)
// This is the sbt plugin
lazy val plugin = (project in file("plugin"))
.enablePlugins(BuildInfoPlugin)
.settings(common: _*)
.settings(scriptedSettings: _*)
.settings(
name := "sbt-play-swagger",
scalaVersion := "2.10.5",
sbtPlugin := true,
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % PlayVersion),
buildInfoKeys := Seq[BuildInfoKey](name, version, scalaVersion, sbtVersion),
buildInfoPackage := "de.zalando",
scriptedLaunchOpts := {
scriptedLaunchOpts.value ++
Seq(
"-Dproject.version=" + version.value,
"-Dscala.version=" + scalaVersion.value,
"-Xmx768M",
"-XX:ReservedCodeCacheSize=256M"
)
},
scriptedDependencies := {
val a = (publishLocal in swaggerModel).value
val b = (publishLocal in api).value
val c = (publishLocal in apiFirstCore).value
val d = (publishLocal in swaggerParser).value
val e = (publishLocal in playScalaGenerator).value
val f = publishLocal.value
},
scriptedBufferLog := false
)
.dependsOn(swaggerModel, swaggerParser, apiFirstCore, playScalaGenerator)
lazy val root = (project in file("."))
// Use sbt-doge cross building since we have different projects with different scala versions
.enablePlugins(CrossPerProjectPlugin)
.settings(common: _*)
.settings(
name := "play-swagger-root"
)
.aggregate(swaggerModel, api, swaggerParser, apiFirstCore, playScalaGenerator, plugin)
def common: Seq[Setting[_]] = bintrayPublishSettings ++ Seq(
organization := "de.zalando",
version := "0.1.10",
fork in ( Test, run ) := true,
autoScalaLibrary := true,
resolvers ++= Seq(
"scalaz-bintray" at "https://dl.bintray.com/scalaz/releases",
"zalando-maven" at "https://dl.bintray.com/zalando/maven"
),
resolvers += Resolver.bintrayRepo("zalando", "sbt-plugins"),
licenses += ("MIT", url("http://opensource.org/licenses/MIT")),
publishMavenStyle := false,
repository in bintray := "sbt-plugins",
bintrayOrganization in bintray := Some("zalando"),
scalacOptions ++= Seq(
"-deprecation",
"-encoding", "UTF-8", // yes, this is 2 args
"-feature",
"-unchecked",
"-Xfatal-warnings",
"-Xlint",
"-Yno-adapted-args",
"-Ywarn-numeric-widen",
"-Ywarn-value-discard",
"-Xfuture"
),
scalastyleFailOnError := true
) ++ addMainSourcesToLintTarget ++ addSlowScalacSwitchesToLintTarget ++ addWartRemoverToLintTarget ++
removeWartRemoverFromCompileTarget ++ addFoursquareLinterToLintTarget ++ removeFoursquareLinterFromCompileTarget
// ++ scalariformSettings
// coverageEnabled := false
coverageMinimum := 80
coverageFailOnMinimum := false
coverageHighlighting := {
if (scalaBinaryVersion.value == "2.10") false
else false
}
// Apply default Scalariform formatting.
// Reformat at every compile.
// c.f. https://github.com/sbt/sbt-scalariform#advanced-configuration for more options.
val LintTarget = config("lint").extend(Compile)
def addMainSourcesToLintTarget: Seq[_root_.sbt.Def.Setting[_]] = {
inConfig(LintTarget) {
// I posted http://stackoverflow.com/questions/27575140/ and got back the bit below as the magic necessary
// to create a separate lint target which we can run slow static analysis on.
Defaults.compileSettings ++ Seq(
sources in LintTarget := {
val lintSources = (sources in LintTarget).value
lintSources ++ (sources in Compile).value
}
)
}
}
def addSlowScalacSwitchesToLintTarget: Seq[_root_.sbt.Def.Setting[_]] = {
inConfig(LintTarget) {
// In addition to everything we normally do when we compile, we can add additional scalac switches which are
// normally too time consuming to run.
scalacOptions in LintTarget ++= Seq(
// As it says on the tin, detects unused imports. This is too slow to always include in the build.
// "-Ywarn-unused-import",
//This produces errors you don't want in development, but is useful.
"-Ywarn-dead-code"
)
}
}
def addWartRemoverToLintTarget: Seq[_root_.sbt.Def.Setting[_]] = {
import wartremover._
import Wart._
// I didn't simply include WartRemove in the build all the time because it roughly tripled compile time.
inConfig(LintTarget) {
wartremoverErrors ++= Seq(
// Ban inferring Any, Serializable, and Product because such inference usually indicates a code error.
Wart.Any,
Wart.Serializable,
Wart.Product,
// Ban calling partial methods because they behave surprisingly
Wart.ListOps,
Wart.OptionPartial,
Wart.EitherProjectionPartial,
// Ban applying Scala's implicit any2String because it usually indicates a code error.
Wart.Any2StringAdd
)
}
}
def removeWartRemoverFromCompileTarget: _root_.sbt.Def.Setting[_root_.sbt.Task[Seq[String]]] = {
// WartRemover's sbt plugin calls addCompilerPlugin which always adds directly to the Compile configuration.
// The bit below removes all switches that could be passed to scalac about WartRemover during a non-lint compile.
scalacOptions in Compile := (scalacOptions in Compile).value filterNot { switch =>
switch.startsWith("-P:wartremover:") ||
"^-Xplugin:.*/org[.]brianmckenna/.*wartremover.*[.]jar$".r.pattern.matcher(switch).find
}
}
def addFoursquareLinterToLintTarget: Seq[_root_.sbt.Def.Setting[_ >: _root_.sbt.Task[Seq[String]] with Seq[_root_.sbt.ModuleID] <: Equals]] = {
Seq(
addCompilerPlugin("org.psywerx.hairyfotr" %% "linter" % "0.1.12"),
// See https://github.com/HairyFotr/linter#list-of-implemented-checks for a list of checks that foursquare linter
// implements
// By default linter enables all checks.
// I don't mind using match on boolean variables.
scalacOptions in LintTarget += "-P:linter:disable:PreferIfToBooleanMatch"
)
}
def removeFoursquareLinterFromCompileTarget: _root_.sbt.Def.Setting[_root_.sbt.Task[Seq[String]]] = {
// We call addCompilerPlugin in project/plugins.sbt to add a depenency on the foursquare linter so that sbt magically
// manages the JAR for us. Unfortunately, addCompilerPlugin also adds a switch to scalacOptions in the Compile config
// to load the plugin.
// The bit below removes all switches that could be passed to scalac about Foursquare Linter during a non-lint compile.
scalacOptions in Compile := (scalacOptions in Compile).value filterNot { switch =>
switch.startsWith("-P:linter:") ||
"^-Xplugin:.*/org[.]psywerx[.]hairyfotr/.*linter.*[.]jar$".r.pattern.matcher(switch).find
}
}