-
Notifications
You must be signed in to change notification settings - Fork 55
/
build.sbt
263 lines (232 loc) · 9.39 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
import com.typesafe.sbt.pgp.PgpKeys._
import Helpers._
// shadow sbt-scalajs' crossProject and CrossType from Scala.js 0.6.x
import sbtcrossproject.CrossPlugin.autoImport.{crossProject, CrossType}
lazy val publishSettings = Seq(
publishTo := {
val nexus = "https://oss.sonatype.org/"
if ( version.value.trim.endsWith( "SNAPSHOT" ) )
Some( "snapshots" at nexus + "content/repositories/snapshots" )
else
Some( "releases" at nexus + "service/local/staging/deploy/maven2" )
},
publishMavenStyle := true,
scmInfo := Some( ScmInfo( url( "https://github.com/wix/accord" ), "scm:git:[email protected]:wix/accord.git" ) ),
pomExtra in ThisBuild :=
<developers>
<developer>
<id>Holograph</id>
<name>Tomer Gabel</name>
<url>http://www.tomergabel.com</url>
</developer>
</developers>
)
lazy val releaseSettings = Seq(
releaseCrossBuild := true,
releasePublishArtifactsAction := publishSigned.value
)
def add213CrossDirs(config: Configuration): Seq[Setting[_]] = Seq(
unmanagedSourceDirectories in config += {
val sourceDir = (sourceDirectory in config).value
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, n)) if n >= 13 => sourceDir / "scala_2.13+"
case _ => sourceDir / "scala_2.13-"
}
}
)
val crossBuildMultipleSourcesOptions = add213CrossDirs(Compile) ++ add213CrossDirs(Test)
def noFatalWarningsOn( task: sbt.TaskKey[_] = compile, configuration: sbt.Configuration = Compile ) =
task match {
case `compile` =>
scalacOptions in configuration ~= { _ filterNot { _ == "-Xfatal-warnings" } }
case _ =>
scalacOptions in ( configuration, task ) :=
( scalacOptions in ( Compile, compile ) ).value filterNot { _ == "-Xfatal-warnings" }
}
// Necessary to work around scala/scala-dev#275 (see wix/accord#84)
def providedScalaCompiler =
libraryDependencies += "org.scala-lang" % "scala-compiler" % scalaVersion.value % "provided"
def limitPackageSize( allowedSizeInKB: Int ) =
packageBin in Compile := {
val jar = ( packageBin in Compile ).value
val sizeKB = jar.length() / 1024
if ( sizeKB > allowedSizeInKB )
sys.error( s"Resulting package $jar (size=${sizeKB}KB) is larger than the allowed limit of ${allowedSizeInKB}KB" )
jar
}
lazy val compileOptions = Seq(
scalaVersion := "2.13.1",
crossScalaVersions := ( Helpers.javaVersion match {
case v if v >= 1.8 => Seq( "2.11.12", "2.12.10", "2.13.1" )
case _ => Seq( "2.11.12" )
} ),
scalacOptions ++= Seq(
"-language:reflectiveCalls",
"-feature",
"-deprecation",
"-unchecked",
"-Xfatal-warnings"
),
noFatalWarningsOn( task = doc ) // Warnings aren't considered fatal on document generation
) ++ providedScalaCompiler
lazy val baseSettings =
publishSettings ++
releaseSettings ++
compileOptions ++
Seq(
organization := "com.wix",
homepage := Some( url( "https://github.com/wix/accord" ) ),
licenses := Seq( "Apache-2.0" -> url( "http://www.opensource.org/licenses/Apache-2.0" ) )
)
lazy val noPublish = Seq( publish := {}, publishLocal := {}, publishArtifact := false )
// Projects --
lazy val api =
crossProject( JVMPlatform, JSPlatform )
.crossType( CrossType.Pure )
.in( file( "api" ) )
.settings( Seq(
name := "accord-api",
description :=
"Accord is a validation library written in and for Scala. Its chief aim is to provide a composable, " +
"dead-simple and self-contained story for defining validation rules and executing them on object " +
"instances. Feedback, bug reports and improvements are welcome!",
libraryDependencies += "org.scalatest" %%% "scalatest" % "3.1.1" % "test",
noFatalWarningsOn( configuration = Test )
) ++ baseSettings :_* )
.jsSettings( limitPackageSize( 160 ) )
.jvmSettings( limitPackageSize( 90 ) )
lazy val scalatest =
crossProject( JVMPlatform, JSPlatform )
.crossType( CrossType.Pure )
.in( file( "scalatest" ) )
.dependsOn( api )
.settings( baseSettings ++ Seq(
name := "accord-scalatest",
description := "ScalaTest matchers for the Accord validation library",
libraryDependencies += "org.scalatest" %%% "scalatest" % "3.1.1",
noFatalWarningsOn( configuration = Test )
) :_* )
.jsSettings( limitPackageSize( 110 ) )
.jvmSettings( limitPackageSize( 60 ) )
lazy val specs2 =
crossProject( JVMPlatform, JSPlatform )
.crossType( CrossType.Pure )
.in( file( "specs2" ) )
.dependsOn( api )
.settings( baseSettings ++ Seq(
name := "accord-specs2",
description := "Specs² matchers for the Accord validation library",
libraryDependencies += "org.specs2" %%% "specs2-core" % "4.9.2",
noFatalWarningsOn( compile, Test )
) :_* )
.jsSettings( limitPackageSize( 110 ) )
.jvmSettings( limitPackageSize( 80 ) )
lazy val core =
crossProject( JVMPlatform, JSPlatform )
.crossType( CrossType.Pure )
.in( file( "core" ) )
.dependsOn( api, scalatest % "test->compile" )
.settings( Seq(
name := "accord-core",
libraryDependencies += "org.scalamacros" %% "resetallattrs" % "1.0.0",
libraryDependencies += "org.scala-lang" % "scala-reflect" % scalaVersion.value % "provided",
description :=
"Accord is a validation library written in and for Scala. Its chief aim is to provide a composable, " +
"dead-simple and self-contained story for defining validation rules and executing them on object " +
"instances. Feedback, bug reports and improvements are welcome!",
noFatalWarningsOn( configuration = Test ), // Avoid failed test compilation due to deprecations // TODO remove
// Scala 2.13 deprecates a number of older collection traits like Traversable and the family of Gen*
// traits. Maintaining backwards compatibility with <2.13 requires keeping these APIs as is, and because
// there's no way to specifically suppress specific warnings by type OR by scope, we have to do this
// wholesale.
noFatalWarningsOn( configuration = Compile )
) ++ baseSettings :_* )
.jvmSettings( limitPackageSize( 500 ) )
.jsSettings( limitPackageSize( 800 ) )
lazy val java8 =
crossProject( JVMPlatform, JSPlatform )
.crossType( CrossType.Pure )
.in( file( "java8" ) )
.dependsOn( api, core, scalatest % "test->compile" )
.settings( Seq(
name := "accord-java8",
description := "Adds native Accord combinators for Java 8 features",
limitPackageSize( 30 )
) ++ baseSettings :_* )
.jsSettings(
// This library is still not complete (e.g. LocalDateTime isn't implemented); Scala.js support
// for this module is consequently currently disabled.
libraryDependencies += "org.scala-js" %%% "scalajs-java-time" % "1.0.0"
)
lazy val joda =
crossProject( JVMPlatform )
.crossType( CrossType.Pure )
.in( file( "joda" ) )
.settings( baseSettings :_* )
.settings(
name := "accord-joda",
libraryDependencies ++= Seq(
"joda-time" % "joda-time" % "2.10.5",
"org.joda" % "joda-convert" % "2.2.1" // Required for rendering constraints
),
description := "Adds native Accord combinators for Joda-Time",
limitPackageSize( 25 )
)
.dependsOn( api, core, scalatest % "test->compile" )
lazy val spring3 =
crossProject( JVMPlatform )
.crossType( CrossType.Pure )
.in( file ( "spring3" ) )
.settings( crossBuildMultipleSourcesOptions )
.settings( baseSettings :_* )
.settings(
name := "accord-spring3",
libraryDependencies ++= Seq(
"org.scala-lang" % "scala-reflect" % scalaVersion.value % "provided",
"javax.validation" % "validation-api" % "1.0.0.GA",
"org.springframework" % "spring-context" % "3.2.18.RELEASE",
"org.springframework" % "spring-test" % "3.2.18.RELEASE" % "test",
"org.apache.bval" % "org.apache.bval.bundle" % "0.5" % "test"
),
description := "Spring 3.x Validation integration for the Accord validation library",
limitPackageSize( 25 )
)
.whenJavaVersion( _ >= 1.9 ) { _.settings(
libraryDependencies ++= Seq(
"javax.xml.bind" % "jaxb-api" % "2.3.1",
"javax.annotation" % "javax.annotation-api" % "1.3.2",
"org.apache.commons" % "commons-lang3" % "3.9"
)
) }
.dependsOn( api, scalatest % "test->compile", core % "test->compile" )
lazy val examples =
crossProject( JVMPlatform )
.crossType( CrossType.Pure )
.in( file( "examples" ) )
.settings( baseSettings :_* )
.settings( noPublish :_* )
.settings(
name := "accord-examples",
description := "Sample projects for the Accord validation library.",
noFatalWarningsOn( configuration = Compile )
)
.dependsOn( api, core, scalatest % "test->compile", specs2 % "test->compile", spring3 )
// Roots --
lazy val jvmRoot =
project
.settings( baseSettings :_* )
.settings( noPublish :_* )
.aggregate( api.jvm, core.jvm, scalatest.jvm, specs2.jvm, spring3.jvm, joda.jvm, examples.jvm )
.whenJavaVersion( _ >= 1.8 ) { _.aggregate( java8.jvm ) }
lazy val jsRoot =
project
.settings( baseSettings :_* )
.settings( noPublish :_* )
.aggregate( api.js, core.js, scalatest.js )
// .whenJavaVersion( _ >= 1.8 ) { _.aggregate( java8.js ) }
lazy val root =
project
.in( file( "." ) )
.settings( baseSettings :_* )
.settings( noPublish :_* )
.aggregate( jvmRoot, jsRoot )