This repository has been archived by the owner on Sep 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 142
/
BuildSettings.scala
256 lines (227 loc) · 8.17 KB
/
BuildSettings.scala
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
/**
* Copyright 2015 Mohiva Organisation (license at mohiva dot com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import com.typesafe.sbt.SbtGhPages.GhPagesKeys._
import com.typesafe.sbt.SbtGhPages.ghpages
import com.typesafe.sbt.SbtGit.git
import com.typesafe.sbt.SbtSite.SiteKeys._
import com.typesafe.sbt.SbtSite.site
import sbt.Keys._
import sbt._
import sbtunidoc.ScalaUnidocPlugin.autoImport._
////*******************************
//// Basic settings
////*******************************
object BasicSettings extends AutoPlugin {
override def trigger = allRequirements
val `scalacOptions2.11.x` = Seq(
"-Ywarn-adapted-args",
"-Ywarn-inaccessible",
"-Ywarn-infer-any",
"-Ywarn-nullary-override",
"-Ywarn-dead-code",
"-Ywarn-nullary-unit",
"-Ywarn-numeric-widen",
"-Xmax-classfile-name", "254",
"-language:higherKinds"
)
val `scalacOptions2.12.x` = Seq(
"-Xlint:adapted-args",
"-Ywarn-inaccessible",
"-Ywarn-infer-any",
"-Xlint:nullary-override",
"-Xlint:nullary-unit",
"-Xmax-classfile-name", "254",
"-language:higherKinds"
)
val `scalacOptions2.13.x` = Seq(
"-Xlint:adapted-args",
"-Xlint:inaccessible",
"-Xlint:infer-any",
"-Xlint:nullary-override",
"-Xlint:nullary-unit"
)
val scalacOptionsCommon = Seq(
"-unchecked",
"-deprecation",
"-feature",
"-encoding", "utf8",
"-Xfatal-warnings",
"-Xlint"
)
override def projectSettings = Seq(
organization := "com.mohiva",
version := "6.1.1",
resolvers ++= Dependencies.resolvers,
scalaVersion := "2.13.1",
crossVersion := CrossVersion.full,
scalacOptions ++= {
scalacOptionsCommon ++ (scalaBinaryVersion.value match {
case "2.11" => `scalacOptions2.11.x`
case "2.12" => `scalacOptions2.12.x`
case "2.13" => `scalacOptions2.13.x`
})
},
scalacOptions in Test ~= { options: Seq[String] =>
options filterNot (_ == "-Ywarn-dead-code") // Allow dead code in tests (to support using mockito).
},
parallelExecution in Test := false,
fork in Test := true,
// Needed to avoid https://github.com/travis-ci/travis-ci/issues/3775 in forked tests
// in Travis with `sudo: false`.
// See https://github.com/sbt/sbt/issues/653
// and https://github.com/travis-ci/travis-ci/issues/3775
javaOptions += "-Xmx1G"
)
}
////*******************************
//// Scalariform settings
////*******************************
object CodeFormatter extends AutoPlugin {
import com.typesafe.sbt.SbtScalariform._
import scalariform.formatter.preferences._
lazy val BuildConfig = config("build") extend Compile
lazy val BuildSbtConfig = config("buildsbt") extend Compile
lazy val prefs = Seq(
ScalariformKeys.preferences := ScalariformKeys.preferences.value
.setPreference(FormatXml, false)
.setPreference(DoubleIndentClassDeclaration, false)
.setPreference(AlignSingleLineCaseStatements, true)
.setPreference(DanglingCloseParenthesis, Preserve)
)
override def trigger = allRequirements
override def projectSettings = defaultScalariformSettings ++ prefs ++
inConfig(BuildConfig)(configScalariformSettings) ++
inConfig(BuildSbtConfig)(configScalariformSettings) ++
Seq(
scalaSource in BuildConfig := baseDirectory.value / "project",
scalaSource in BuildSbtConfig := baseDirectory.value / "project",
includeFilter in (BuildConfig, ScalariformKeys.format) := ("*.scala": FileFilter),
includeFilter in (BuildSbtConfig, ScalariformKeys.format) := ("*.sbt": FileFilter),
ScalariformKeys.format in Compile := {
(ScalariformKeys.format in BuildSbtConfig).value
(ScalariformKeys.format in BuildConfig).value
(ScalariformKeys.format in Compile).value
}
)
}
////*******************************
//// ScalaDoc settings
////*******************************
object Doc extends AutoPlugin {
import play.core.PlayVersion
override def projectSettings = Seq(
autoAPIMappings := true,
apiURL := Some(url(s"http://api.silhouette.mohiva.com/${version.value}/")),
apiMappings ++= {
implicit val cp = (fullClasspath in Compile).value
Map(
jarFor("com.typesafe.play", "play") -> url(s"http://www.playframework.com/documentation/${PlayVersion.current}/api/scala/"),
scalaInstance.value.libraryJar -> url(s"http://www.scala-lang.org/api/${scalaVersion.value}/")
)
}
)
/**
* Gets the JAR file for a package.
*
* @param organization The organization name.
* @param name The name of the package.
* @param cp The class path.
* @return The file which points to the JAR.
* @see http://stackoverflow.com/a/20919304/2153190
*/
private def jarFor(organization: String, name: String)(implicit cp: Seq[Attributed[File]]): File = {
(for {
entry <- cp
module <- entry.get(moduleID.key)
if module.organization == organization
if module.name.startsWith(name)
jarFile = entry.data
} yield jarFile).head
}
}
////*******************************
//// APIDoc settings
////*******************************
// @see https://github.com/paypal/horizon/blob/develop/src/main/scala/com/paypal/horizon/BuildUtilities.scala
object APIDoc {
lazy val files = Seq(file("CNAME"))
lazy val settings =
site.settings ++
ghpages.settings ++
Seq(
// Create version
siteMappings ++= {
val mapping = (mappings in (ScalaUnidoc, packageDoc)).value
val ver = version.value
for ((file, path) <- mapping) yield (file, s"$ver/$path")
},
// Add custom files from site directory
siteMappings ++= baseDirectory.map { dir =>
for (file <- files) yield (new File(dir.getAbsolutePath + "/site/" + file), file.name)
}.value,
// Do not delete old versions
synchLocal := {
val betterMappings = privateMappings.value.map { case (file, tgt) => (file, updatedRepository.value / tgt) }
IO.copy(betterMappings)
updatedRepository.value
},
git.remoteRepo := "git@github.com:mohiva/play-silhouette.git"
)
}
////*******************************
//// Maven settings
////*******************************
object Publish extends AutoPlugin {
import xerial.sbt.Sonatype._
override def trigger = allRequirements
private val pom = {
<scm>
<url>git@github.com:mohiva/play-silhouette.git</url>
<connection>scm:git:git@github.com:mohiva/play-silhouette.git</connection>
</scm>
<developers>
<developer>
<id>akkie</id>
<name>Christian Kaps</name>
<url>http://mohiva.com</url>
</developer>
<developer>
<id>fernandoacorreia</id>
<name>Fernando Correia</name>
<url>http://www.fernandocorreia.info/</url>
</developer>
</developers>
}
override def projectSettings = sonatypeSettings ++ Seq(
description := "Authentication library for Play Framework applications that supports several authentication methods, including OAuth1, OAuth2, OpenID, CAS, Credentials, Basic Authentication, Two Factor Authentication or custom authentication schemes",
homepage := Some(url("http://www.silhouette.rocks/")),
licenses := Seq("Apache License" -> url("https://github.com/mohiva/play-silhouette/blob/master/LICENSE")),
publishMavenStyle := true,
publishArtifact in Test := false,
pomIncludeRepository := { _ => false },
pomExtra := pom
)
}
////*******************************
//// Helpers
////*******************************
object Util {
def priorTo213(scalaVersion: String): Boolean =
CrossVersion.partialVersion(scalaVersion) match {
case Some((2, minor)) if minor < 13 => true
case _ => false
}
}