forked from playframework/play-json
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sbt
252 lines (220 loc) · 8.64 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
/*
* Copyright (C) 2009-2019 Lightbend Inc. <https://www.lightbend.com>
*/
import interplay.ScalaVersions
import ReleaseTransformations._
import com.typesafe.tools.mima.core._
import com.typesafe.tools.mima.plugin.MimaPlugin.mimaDefaultSettings
import com.typesafe.tools.mima.plugin.MimaKeys.{
mimaBinaryIssueFilters, mimaPreviousArtifacts
}
import sbtcrossproject.{crossProject, CrossType}
resolvers ++= DefaultOptions.resolvers(snapshot = true)
val specsBuild = Def.setting[Seq[ModuleID]] {
val specsVersion = CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 10)) => "3.9.1"
case _ => "4.3.5"
}
Seq("org.specs2" %% "specs2-core" % specsVersion)
}
val jacksonVersion = "2.9.8"
val jacksons = Seq(
"com.fasterxml.jackson.core" % "jackson-core",
"com.fasterxml.jackson.core" % "jackson-annotations",
"com.fasterxml.jackson.core" % "jackson-databind",
"com.fasterxml.jackson.datatype" % "jackson-datatype-jdk8",
"com.fasterxml.jackson.datatype" % "jackson-datatype-jsr310"
).map(_ % jacksonVersion)
val joda = Seq(
"joda-time" % "joda-time" % "2.10.1"
//"org.joda" % "joda-convert" % "1.8.1")
)
def jsonDependencies(scalaVersion: String) = Seq(
"org.scala-lang" % "scala-reflect" % scalaVersion
)
// Common settings
import com.typesafe.sbt.SbtScalariform, SbtScalariform.ScalariformKeys
import scalariform.formatter.preferences._
val previousVersions = Def.setting[Seq[String]] {
Nil // Seq("2.8.0-M1") // TODO: switch to a release of 2.8, when available
}
def playJsonMimaSettings = mimaDefaultSettings ++ Seq(
mimaPreviousArtifacts := previousVersions.value.map(organization.value %%% moduleName.value % _).toSet
)
// Workaround for https://github.com/scala-js/scala-js/issues/2378
// Use "sbt -DscalaJSStage=full" in .travis.yml
scalaJSStage in ThisBuild := (sys.props.get("scalaJSStage") match {
case Some("full") => FullOptStage
case _ => FastOptStage
})
lazy val commonSettings = SbtScalariform.projectSettings ++ Seq(
// Do not buffer test output
logBuffered in Test := false,
testOptions in Test ++= Seq(
// Show the duration of tests
Tests.Argument(TestFrameworks.ScalaTest, "-oD"),
Tests.Argument(TestFrameworks.Specs2, "showtimes"),
// Filtering tests that are not stable in Scala 2.13 yet.
Tests.Argument(TestFrameworks.ScalaTest, "-l", "play.api.libs.json.UnstableInScala213")
),
publishTo := Some(
if (isSnapshot.value)
Opts.resolver.sonatypeSnapshots
else
Opts.resolver.sonatypeStaging
),
scalariformAutoformat := true,
headerLicense := {
val currentYear = java.time.Year.now(java.time.Clock.systemUTC).getValue
Some(HeaderLicense.Custom(
s"Copyright (C) 2009-$currentYear Lightbend Inc. <https://www.lightbend.com>"
))
},
scalaVersion := ScalaVersions.scala212,
crossScalaVersions := Seq(
ScalaVersions.scala211, ScalaVersions.scala212, ScalaVersions.scala213
),
ScalariformKeys.preferences := ScalariformKeys.preferences.value
.setPreference(SpacesAroundMultiImports, true)
.setPreference(SpaceInsideParentheses, false)
.setPreference(DanglingCloseParenthesis, Preserve)
.setPreference(PreserveSpaceBeforeArguments, true)
.setPreference(DoubleIndentConstructorArguments, false)
)
lazy val root = project
.in(file("."))
.enablePlugins(PlayRootProject, ScalaJSPlugin)
.aggregate(
`play-jsonJS`,
`play-jsonJVM`,
`play-functionalJS`,
`play-functionalJVM`,
`play-json-joda`
).settings(
commonSettings,
publishTo := None
)
lazy val `play-json` = crossProject(JVMPlatform, JSPlatform).crossType(CrossType.Full)
.in(file("play-json"))
.enablePlugins(PlayLibrary, Playdoc)
.settings(commonSettings)
.settings(playJsonMimaSettings)
.settings(
mimaBinaryIssueFilters ++= Seq(),
libraryDependencies ++= jsonDependencies(scalaVersion.value) ++ Seq(
"org.scalatest" %%% "scalatest" % "3.0.6-SNAP4" % Test,
"org.scalacheck" %%% "scalacheck" % "1.14.0" % Test,
"com.chuusai" %% "shapeless" % "2.3.3" % Test,
"org.typelevel" %% "macro-compat" % "1.1.1",
"org.scala-lang" % "scala-compiler" % scalaVersion.value % "provided"
),
libraryDependencies ++=
(CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 13)) => Seq("org.scala-lang.modules" %%% "scala-collection-compat" % "0.2.0")
case _ => Seq("org.scala-lang.modules" %%% "scala-collection-compat" % "0.1.1")
}),
libraryDependencies ++=
(CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 13)) => Seq()
case _ => Seq(compilerPlugin("org.scalamacros" % "paradise" % "2.1.0" cross CrossVersion.full))
}),
sourceGenerators in Compile += Def.task{
val dir = (sourceManaged in Compile).value
val file = dir / "upickle" / "Generated.scala"
val (writes, reads) = (1 to 22).map{ i =>
def commaSeparated(s: Int => String) = (1 to i).map(s).mkString(", ")
def newlineSeparated(s: Int => String) = (1 to i).map(s).mkString("\n")
val writerTypes = commaSeparated(j => s"T$j: Writes")
val readerTypes = commaSeparated(j => s"T$j: Reads")
val typeTuple = commaSeparated(j => s"T$j")
val written = commaSeparated(j => s"implicitly[Writes[T$j]].writes(x._$j)")
val readValues = commaSeparated(j => s"t$j")
val readGenerators = newlineSeparated(j => s"t$j <- implicitly[Reads[T$j]].reads(arr(${j-1}))")
(s"""
implicit def Tuple${i}W[$writerTypes]: Writes[Tuple${i}[$typeTuple]] = Writes[Tuple${i}[$typeTuple]](
x => JsArray(Array($written))
)
""",s"""
implicit def Tuple${i}R[$readerTypes]: Reads[Tuple${i}[$typeTuple]] = Reads[Tuple${i}[$typeTuple]]{
case JsArray(arr) if arr.size == $i =>
for{
$readGenerators
} yield Tuple$i($readValues)
case _ =>
JsError(Seq(JsPath() -> Seq(JsonValidationError("Expected array of $i elements"))))
}
""")
}.unzip
IO.write(file, s"""
package play.api.libs.json
trait GeneratedReads {
${reads.mkString("\n")}
}
trait GeneratedWrites{
${writes.mkString("\n")}
}
""")
Seq(file)
}.taskValue
)
.dependsOn(`play-functional`)
lazy val `play-json-joda` = project
.in(file("play-json-joda"))
.enablePlugins(PlayLibrary)
.settings(commonSettings)
.settings(playJsonMimaSettings)
.settings(
libraryDependencies ++= joda ++ specsBuild.value.map(_ % Test)
)
.dependsOn(`play-jsonJVM`)
lazy val `play-jsonJVM` = `play-json`.jvm.
settings(
libraryDependencies ++=
joda ++ // TODO: remove joda after 2.6.0
jacksons ++ specsBuild.value.map(_ % Test) :+ (
"ch.qos.logback" % "logback-classic" % "1.2.3" % Test
),
unmanagedSourceDirectories in Test ++= (baseDirectory.value / ".." / ".." / "docs" / "manual" / "working" / "scalaGuide" ** "code").get
)
lazy val `play-jsonJS` = `play-json`.js
lazy val `play-functional` = crossProject(JVMPlatform, JSPlatform).crossType(CrossType.Pure)
.in(file("play-functional"))
.settings(commonSettings ++ playJsonMimaSettings ++ Seq(
mimaBinaryIssueFilters ++= Seq()
))
.enablePlugins(PlayLibrary)
lazy val `play-functionalJVM` = `play-functional`.jvm
lazy val `play-functionalJS` = `play-functional`.js
lazy val benchmarks = project
.in(file("benchmarks"))
.enablePlugins(JmhPlugin, PlayNoPublish)
.settings(commonSettings)
.dependsOn(`play-jsonJVM`)
playBuildRepoName in ThisBuild := "play-json"
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
)
lazy val checkCodeFormat = taskKey[Unit]("Check that code format is following Scalariform rules")
checkCodeFormat := {
val exitCode = "git diff --exit-code".!
if (exitCode != 0) {
sys.error(
"""
|ERROR: Scalariform check failed, see differences above.
|To fix, format your sources using sbt scalariformFormat test:scalariformFormat before submitting a pull request.
|Additionally, please squash your commits (eg, use git commit --amend) if you're going to update this pull request.
""".stripMargin)
}
}
addCommandAlias("validateCode", ";scalariformFormat;test:scalariformFormat;headerCheck;test:headerCheck;checkCodeFormat")