-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathbuild.sbt
380 lines (328 loc) · 13.7 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
name := "aloha"
description := "Scala-based machine learning library with generic models and lazily created features."
// ===========================================================================
// Build Settings
// ===========================================================================
incOptions := incOptions.value.withNameHashing(true)
// This can yield significant improvements in artifact resolution and
// compilation speeds. See:
// https://www.lightbend.com/blog/improved-dependency-management-with-sbt-0137
updateOptions := updateOptions.value.withCachedResolution(true)
lazy val commonSettings = Seq(
organization := "com.eharmony",
scalaVersion := "2.11.12",
crossScalaVersions := Seq("2.10.5", "2.11.12"),
crossPaths := true,
incOptions := incOptions.value.withNameHashing(true),
javacOptions ++= Seq("-Xlint:unchecked"),
resolvers ++= Seq(
Resolver.sonatypeRepo("releases"),
Resolver.sonatypeRepo("snapshots")
),
scalacOptions ++= Seq(
// "-verbose",
"-unchecked",
"-deprecation",
"-feature",
"-Xverify",
"-Ywarn-inaccessible",
"-Ywarn-dead-code",
// Compile errors occur when omitted in 2.10 because of a scala language bug.
"-Ycheck:jvm"
),
// Set the dependency conflict resolution behavior. For more info, see:
// http://www.scala-sbt.org/0.13/api/index.html#sbt.ConflictManager$
// https://ant.apache.org/ivy/history/latest-milestone/settings/conflict-managers.html
conflictManager := ConflictManager.strict,
// See: http://www.scala-sbt.org/release/docs/Running-Project-Code.html
// fork := true is needed; otherwise we see error:
//
// Test com.eharmony.aloha.models.CategoricalDistibutionModelTest.testSerialization
// failed: java.lang.ClassCastException: cannot assign instance of
// scala.collection.immutable.List$SerializationProxy to field
// com.eharmony.aloha.models.CategoricalDistibutionModel.features of type
// scala.collection.Seq in instance of
// com.eharmony.aloha.models.CategoricalDistibutionModel
fork := true,
// This is required to avoid Travis failures in sbt.ForkMain with message
// "failed with exit code 137". This is an issue others have when forking.
javaOptions ++= Seq("-Xmx2g"),
// Because 2.10 runtime reflection is not thread-safe, tests fail non-deterministically.
// This is a hack to make tests pass by not allowing the tests to run in parallel.
parallelExecution in Test := false
)
lazy val versionDependentSettings = Seq(
scalacOptions ++= {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, scalaMajor)) if scalaMajor == 10 => Seq(
// "-Yinline",
"-Yclosure-elim",
"-Ydead-code",
"-Ywarn-all"
)
case Some((2, scalaMajor)) if scalaMajor == 11 => Seq(
"-Ywarn-unused",
"-Ywarn-unused-import",
// "-Yinline",
"-Yclosure-elim",
"-Ydead-code" //,
// "-Xlog-implicit-conversions",
// "-Xlog-implicits"
)
case _ => Seq()
}
}
)
// ===========================================================================
// Resource Filtering
// ===========================================================================
// Since `flatten` is a very generic name, Alias it to avoid conflicts with keys in other plugins.
import EditSourcePlugin.autoImport.{flatten => editFlatten}
import com.sun.java.swing.plaf.windows.WindowsInternalFrameTitlePane.ScalableIconUIResource
def editSourceSettings = Seq[Setting[_]](
// This might be the only one that requires def instead of lazy val:
targetDirectory in EditSource := (crossTarget.value / "filtered"),
// These don't change per project and should be OK with a lazy val instead of def:
editFlatten in EditSource := false,
(sources in EditSource) ++= baseDirectory.map { d =>
(d / "src" / "main" / "filtered_resources" / "" ** "*.*").get ++
(d / "src" / "test" / "filtered_resources" / "" ** "*.*").get
}.value,
variables in EditSource += crossTarget {t => ("projectBuildDirectory", t.getCanonicalPath)}.value,
variables in EditSource += (sourceDirectory in Test) {s => ("scalaTestSource", s.getCanonicalPath)}.value,
variables in EditSource += version {s => ("projectVersion", s.toString)}.value,
// Try doing this with adding to sourceManaged direcory instead of directly
// adding to the class directory in the compile task. This would most likely
// be better because we could incorporate src/main/scala if we wanted. This
// could easily be accomplished if we rename the filtered_resources directory
// and add an indicator in the file names (like __filtered__ or something).
// For instance, do something like this:
//
// mySourceGenerator in Compile := {
// generate( (sourceManaged in Compile).value / "some_directory")
// }
//
compile in Compile := {
val c = (compile in Compile).value
filteredTask.value
c
}
)
/**
* This task moves the filtered files to the proper target directory. It is
* based on specific EditSource settings, especially that filtered_resources
* is the only directory in which EditSource searches.
*/
lazy val filteredTask = Def.task {
val s = streams.value
val files = (edit in EditSource).value
// This directory is dependent on the target of EditSource. It assumes that
// it is crossTarget / "filtered".
val slash = System.getProperty("file.separator", "/")
val components = ("^(.*)/filtered/src/(main|test)/filtered_resources/(.*)$").r
val mappings = files map { f =>
// Replace in case this bombs in Windows.
val newF = f.getCanonicalPath.replace(slash, "/") match {
case components(prefix, srcType, suffix) =>
// This could probably be more robust.
val classDir = if (srcType == "test") "test-classes" else "classes"
file(prefix) / classDir / suffix
}
(f, newF)
}
mappings foreach { case (f, t) =>
val msg = s"""Moving "$f" -> "$t""""
s.log.info(msg)
val success = ((t.getParentFile.exists || t.getParentFile.mkdirs()) && f.renameTo(t))
if (!success) s.log.error(s"Failure $msg")
}
}
// ===========================================================================
// Other Common Settings
// ===========================================================================
lazy val noPublishSettings = Seq(
publish := { },
publishM2 := { },
publishLocal := { },
publishArtifact := false
)
// ===========================================================================
// Modules
// ===========================================================================
lazy val root = project.in(file("."))
.aggregate(core, vwJni, h2o, cli, ioProto, avroScoreJava, ioAvro, docs)
.dependsOn(core, vwJni, h2o, cli, ioProto, avroScoreJava, ioAvro, docs)
.settings(commonSettings: _*)
.settings(versionDependentSettings: _*)
.settings(dependencyOverrides ++= Dependencies.overrideDeps)
.settings(noPublishSettings)
// .enablePlugins(ScalaUnidocPlugin)
lazy val core = project.in(file("aloha-core"))
.settings(name := "aloha-core")
.settings(commonSettings: _*)
.settings(versionDependentSettings: _*)
.settings(editSourceSettings: _*)
.settings(libraryDependencies ++= Seq(
"org.scala-lang" % "scala-reflect" % scalaVersion.value,
"org.scala-lang" % "scala-compiler" % scalaVersion.value
) ++ Dependencies.coreDeps)
.settings(dependencyOverrides ++= Dependencies.overrideDeps)
lazy val vwJni = project.in(file("aloha-vw-jni"))
.settings(name := "aloha-vw-jni")
.dependsOn(core % "test->test;compile->compile")
.settings(commonSettings: _*)
.settings(versionDependentSettings: _*)
.settings(editSourceSettings: _*)
.settings(libraryDependencies ++= Dependencies.vwJniDeps)
.settings(dependencyOverrides ++= Dependencies.overrideDeps)
lazy val h2o = project.in(file("aloha-h2o"))
.settings(name := "aloha-h2o")
.dependsOn(core % "test->test;compile->compile", ioProto % "test->test")
.settings(commonSettings: _*)
.settings(versionDependentSettings: _*)
.settings(editSourceSettings: _*)
.settings(libraryDependencies ++= Dependencies.h2oDeps)
.settings(dependencyOverrides ++= Dependencies.overrideDeps)
lazy val ioProto = project.in(file("aloha-io-proto"))
.settings(name := "aloha-io-proto")
.dependsOn(core % "test->test;compile->compile")
.settings(commonSettings: _*)
.settings(versionDependentSettings: _*)
.settings(editSourceSettings: _*)
.settings(libraryDependencies ++= Dependencies.ioProtoDeps)
.settings(dependencyOverrides ++= Dependencies.overrideDeps)
lazy val cli = project.in(file("aloha-cli"))
.settings(name := "aloha-cli")
.dependsOn(core % "test->test;compile->compile", vwJni, h2o, ioProto % "test->test;compile->compile")
.settings(commonSettings: _*)
.settings(versionDependentSettings: _*)
.settings(editSourceSettings: _*)
.settings(libraryDependencies ++= Dependencies.cliDeps)
.settings(dependencyOverrides ++= Dependencies.overrideDeps)
// Avro definitions only
lazy val avroScoreJava = project.in(file("aloha-avro-score-java"))
.settings(
name := "aloha-avro-score-java",
organization := "com.eharmony",
crossPaths := false,
resolvers ++= Seq(
Resolver.sonatypeRepo("releases"),
Resolver.sonatypeRepo("snapshots")
),
libraryDependencies := Dependencies.avroScoreJavaDeps
)
lazy val ioAvro = project.in(file("aloha-io-avro"))
.settings(name := "aloha-io-avro")
.dependsOn(core % "test->test;compile->compile", core, avroScoreJava)
.settings(commonSettings: _*)
.settings(versionDependentSettings: _*)
.settings(editSourceSettings: _*)
.settings(libraryDependencies ++= Dependencies.ioAvroDeps)
.settings(dependencyOverrides ++= Dependencies.overrideDeps)
// ===========================================================================
// Release
// ===========================================================================
// run `sbt release`.
// The rest should be fairly straightforward. Follow prompts for things like
// and eventually enter PGP pass phrase.
sonatypeProfileName := "com.eharmony"
pomExtra in Global := (
<url>https://github.com/eharmony/aloha</url>
<licenses>
<license>
<name>MIT License</name>
<url>https://opensource.org/licenses/MIT</url>
<distribution>repo</distribution>
</license>
</licenses>
<developers>
<developer>
<id>deaktator</id>
<name>R M Deak</name>
<url>https://deaktator.github.io</url>
<roles>
<role>creator</role>
<role>developer</role>
</roles>
<timezone>-8</timezone>
</developer>
</developers>
)
import ReleaseTransformations._
releaseCrossBuild := true
releaseProcess := Seq[ReleaseStep](
checkSnapshotDependencies,
inquireVersions,
runClean,
runTest,
setReleaseVersion,
commitReleaseVersion,
tagRelease,
ReleaseStep(action = Command.process("publishSigned", _), enableCrossBuild = true),
setNextVersion,
commitNextVersion,
ReleaseStep(action = Command.process("sonatypeReleaseAll", _), enableCrossBuild = true),
pushChanges
)
// ===========================================================================
// Site
// ===========================================================================
// enablePlugins(GhpagesPlugin)
git.remoteRepo := "[email protected]:eHarmony/aloha.git"
lazy val docsMappingsAPIDir = settingKey[String]("Name of subdirectory in site target directory for api docs")
lazy val docSettings = Seq(
micrositeName := "Aloha",
micrositeDescription := "Generic machine learning, lazy features",
micrositeAuthor := "eHarmony",
micrositeHighlightTheme := "atom-one-light",
micrositeHomepage := "http://eharmony.github.io/aloha",
micrositeOrganizationHomepage := "http://www.eharmony.com",
micrositeBaseUrl := "aloha",
micrositeDocumentationUrl := "docs",
micrositeGithubOwner := "eharmony",
// micrositeExtraMdFiles := Map(file("CONTRIBUTING.md") -> "contributing.md"),
micrositeGithubRepo := "aloha",
micrositePalette := Map(
"brand-primary" -> "#5B5988",
"brand-secondary" -> "#292E53",
"brand-tertiary" -> "#222749",
"gray-dark" -> "#49494B",
"gray" -> "#7B7B7E",
"gray-light" -> "#E5E5E6",
"gray-lighter" -> "#F4F3F4",
"white-color" -> "#FFFFFF"),
autoAPIMappings := true,
unidocProjectFilter in (ScalaUnidoc, unidoc) :=
inProjects(core, vwJni, h2o, ioProto, avroScoreJava, ioAvro, cli),
docsMappingsAPIDir := "docs/api",
addMappingsToSiteDir(mappings in (ScalaUnidoc, packageDoc), docsMappingsAPIDir),
ghpagesNoJekyll := false,
fork in tut := true,
fork in (ScalaUnidoc, unidoc) := true,
// unidoc
// Figure out a way to get this in.
// scalacOptions in (ScalaUnidoc) ++= Seq(
// "-Xfatal-warnings",
// "-doc-source-url", scmInfo.value.get.browseUrl + "/tree/master€{FILE_PATH}.scala",
// "-sourcepath", baseDirectory.in(LocalRootProject).value.getAbsolutePath,
// "-diagrams"
// ),
git.remoteRepo := "[email protected]:eharmony/aloha.git",
includeFilter in makeSite := "**/*.html" | "*.css" | "*.png" | "*.jpg" | "*.gif" | "*.js" | "*.swf" | "*.yml" | "**/*.md"
)
// To see locally: docs/makeMicrosite
lazy val docs = project.in(file("docs"))
.settings(name := "docs")
// .settings(moduleName := "docs")
.enablePlugins(MicrositesPlugin)
.enablePlugins(GhpagesPlugin)
.enablePlugins(ScalaUnidocPlugin)
.settings(commonSettings: _*)
.settings(noPublishSettings)
.settings(GhpagesPlugin.globalSettings: _*)
.settings(docSettings)
.settings(scalacOptions in Tut := Seq("-usejavacp", "-J-Xmx2g"))
.settings(dependencyOverrides ++= Dependencies.overrideDeps)
.dependsOn(core, vwJni, h2o, ioProto % "compile->test;compile->compile", avroScoreJava, ioAvro, cli)
// .settings(tutSettings)
// .settings(tutScalacOptions ~= (_.filterNot(Set("-Ywarn-unused-import", "-Ywarn-dead-code"))))