forked from scalacenter/scalafix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sbt
445 lines (408 loc) · 11.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
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
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
import sbt.ScriptedPlugin._
import Dependencies._
version.in(ThisBuild) ~= { old: String =>
val suffix =
if (sys.props.contains("scalafix.snapshot")) "-SNAPSHOT"
else ""
sys.props.getOrElse("scalafix.version", old.replace('+', '-') + suffix)
}
lazy val scalaFixedProjects: List[ProjectReference] =
List(
testsOutputDotty,
website
)
lazy val scala212Projects: List[ProjectReference] =
List(
cli212,
core212JS,
core212JVM,
diff212JS,
diff212JVM,
reflect212,
testkit212,
testsInput212,
testsOutput212,
testsShared212,
unit212
)
lazy val allScala212Projects: List[ProjectReference] =
scala212Projects ++ scalaFixedProjects
lazy val scala212ProjectsDependencies: List[ClasspathDep[ProjectReference]] =
scala212Projects.map(ClasspathDependency(_, None))
lazy val scala211Projects: List[ProjectReference] =
List(
cli211,
core211JS,
core211JVM,
diff211JS,
diff211JVM,
reflect211,
testkit211,
testsInput211,
testsOutput211,
testsShared211,
unit211
)
lazy val allScala211Projects: List[ProjectReference] =
scala211Projects ++ scalaFixedProjects
lazy val scala211ProjectsDependencies: List[ClasspathDep[ProjectReference]] =
scala211Projects.map(ClasspathDependency(_, None))
lazy val scalafix = project
.in(file("."))
.settings(
moduleName := "scalafixRoot",
onLoadMessage := s"Welcome to Scalafix ${version.value}",
noPublish,
scalaVersion := scala212
)
.aggregate(allScala212Projects: _*)
.dependsOn(scala212ProjectsDependencies: _*)
lazy val scalafix211 = project
.in(file(".scalafix211"))
.settings(
moduleName := "scalafix211",
noPublish,
scalaVersion := scala211
)
.aggregate(allScala211Projects: _*)
.dependsOn(scala211ProjectsDependencies: _*)
val diff = MultiScalaCrossProject(
"diff",
_.settings(
moduleName := "scalafix-diff",
description := "JVM/JS library to build unified diffs."
).jvmSettings(
libraryDependencies += googleDiff
)
.jsSettings(
allJSSettings,
npmDependencies in Compile += "diff" -> "3.2.0"
)
.jsConfigure(_.enablePlugins(ScalaJSBundlerPlugin))
)
val diff211 = diff(scala211)
val diff212 = diff(scala212)
lazy val diff211JVM = diff211.jvm
lazy val diff211JS = diff211.js
lazy val diff212JVM = diff212.jvm
lazy val diff212JS = diff212.js
val core = MultiScalaCrossProject(
"core",
_.settings(
buildInfoSettings,
libraryDependencies ++= List(
scalameta.value,
"org.scala-lang" % "scala-reflect" % scalaVersion.value % Provided
)
).jvmSettings(
libraryDependencies += "com.geirsson" %% "metaconfig-typesafe-config" % metaconfigV
)
.jsSettings(
libraryDependencies += "com.geirsson" %%% "metaconfig-hocon" % metaconfigV
)
.enablePlugins(BuildInfoPlugin)
)
val core211 = core(scala211, _.dependsOn(diff211))
val core212 = core(scala212, _.dependsOn(diff212))
lazy val core211JVM = core211.jvm
lazy val core211JS = core211.js
lazy val core212JVM = core212.jvm
lazy val core212JS = core212.js
val reflect = MultiScalaProject(
"reflect",
_.settings(
isFullCrossVersion,
libraryDependencies ++= Seq(
"org.scala-lang" % "scala-compiler" % scalaVersion.value,
"org.scala-lang" % "scala-reflect" % scalaVersion.value
)
)
)
lazy val reflect211 = reflect(scala211, _.dependsOn(core211JVM))
lazy val reflect212 = reflect(scala212, _.dependsOn(core212JVM))
val cli = MultiScalaProject(
"cli",
_.settings(
isFullCrossVersion,
mainClass in assembly := Some("scalafix.cli.Cli"),
assemblyJarName in assembly := "scalafix.jar",
libraryDependencies ++= Seq(
metacp,
"com.github.alexarchambault" %% "case-app" % "1.2.0",
"org.typelevel" %% "paiges-core" % "0.2.0",
"com.martiansoftware" % "nailgun-server" % "0.9.1",
jgit,
"ch.qos.logback" % "logback-classic" % "1.2.3",
"org.apache.commons" % "commons-text" % "1.2"
)
)
)
lazy val cli211 =
cli(scala211, _.dependsOn(core211JVM, reflect211, testkit211 % Test))
lazy val cli212 =
cli(scala212, _.dependsOn(core212JVM, reflect212, testkit212 % Test))
val scalafixSbt = MultiSbtProject(
"sbt",
_.settings(
buildInfoSettings,
commands += Command.command(
"installCompletions",
"Code generates names of scalafix rules.",
"") { s =>
"cli/run --sbt scalafix-sbt/src/main/scala/scalafix/internal/sbt/ScalafixRuleNames.scala" ::
s
},
scalaVersion := {
CrossVersion.binarySbtVersion(scriptedSbt.value) match {
case "0.13" => scala210
case _ => scala212
}
},
sbtPlugin := true,
libraryDependencies ++= jgit +: coursierDeps,
libraryDependencies += Defaults.sbtPluginExtra(
"com.dwijnand" % "sbt-compat" % "1.2.6",
(sbtBinaryVersion in pluginCrossBuild).value,
(scalaBinaryVersion in update).value
),
testQuick := {}, // these test are slow.
// scripted tests needs scalafix 2.12
// semanticdb-scala will generate the semantic db for both scala 2.11 and scala 2.12
publishLocal := publishLocal
.dependsOn(
publishLocal in diff212JVM,
publishLocal in core212JVM,
publishLocal in reflect212,
publishLocal in cli212)
.value,
moduleName := "sbt-scalafix",
mimaPreviousArtifacts := Set.empty,
scriptedLaunchOpts ++= Seq(
"-Dplugin.version=" + version.value,
// .jvmopts is ignored, simulate here
"-Xmx2g",
"-Xss2m"
),
scriptedBufferLog := false
).enablePlugins(BuildInfoPlugin)
.disablePlugins(ScalafixPlugin)
)
lazy val scalafixSbt1 = scalafixSbt(
scala212,
sbt1,
_.dependsOn(testUtils212 % Test)
)
lazy val scalafixSbt013 = scalafixSbt(
scala210,
sbt013,
_.settings(
scalacOptions -= warnUnusedImports
).dependsOn(testUtils210 % Test)
)
val testUtils = MultiScalaProject(
"test-utils",
_.settings(
libraryDependencies ++= Seq(
jgit,
scalatest
)
)
)
lazy val testUtils210 = testUtils(
scala210,
_.settings(
scalacOptions -= warnUnusedImports
)
)
lazy val testUtils211 = testUtils(scala211)
lazy val testUtils212 = testUtils(scala212)
val testkit = MultiScalaProject(
"testkit",
_.settings(
isFullCrossVersion,
libraryDependencies ++= Seq(
semanticdb,
ammonite,
googleDiff,
scalatest
)
)
)
lazy val testkit211 =
testkit(scala211, _.dependsOn(core211JVM, reflect211, testUtils211))
lazy val testkit212 =
testkit(scala212, _.dependsOn(core212JVM, reflect212, testUtils212))
val testsShared = TestProject(
"shared",
_.settings(
semanticdbSettings,
noPublish
))
lazy val testsShared211 = testsShared(scala211)
lazy val testsShared212 = testsShared(scala212)
val testsInput = TestProject(
"input",
(project, srcMain) =>
project.settings(
noPublish,
semanticdbSettings,
scalacOptions ++= List(
{
val sourceroot = baseDirectory.in(ThisBuild).value / srcMain
s"-P:semanticdb:sourceroot:$sourceroot"
}
),
scalacOptions ~= (_.filterNot(_ == "-Yno-adapted-args")),
scalacOptions += "-Ywarn-adapted-args", // For NoAutoTupling
scalacOptions += "-Ywarn-unused-import", // For RemoveUnusedImports
scalacOptions += "-Ywarn-unused", // For RemoveUnusedTerms
logLevel := Level.Error, // avoid flood of compiler warnings
testsInputOutputSetting
)
)
lazy val testsInput211 = testsInput(scala211, _.dependsOn(testsShared211))
lazy val testsInput212 = testsInput(scala212, _.dependsOn(testsShared212))
val testsOutput = TestProject(
"output",
_.settings(
noPublish,
semanticdbSettings,
scalacOptions --= List(
warnUnusedImports,
"-Xlint"
),
testsInputOutputSetting
))
val testsOutput211 = testsOutput(scala211, _.dependsOn(testsShared211))
val testsOutput212 = testsOutput(scala212, _.dependsOn(testsShared212))
lazy val testsOutputDotty = project
.in(file("scalafix-tests/output-dotty"))
.settings(
noPublish,
// Skip this project for IntellIJ, see https://youtrack.jetbrains.com/issue/SCL-12237
SettingKey[Boolean]("ide-skip-project") := true,
scalaVersion := dotty,
crossScalaVersions := List(dotty),
libraryDependencies := libraryDependencies.value.map(_.withDottyCompat()),
scalacOptions := Nil
)
.disablePlugins(ScalafixPlugin)
def unit(
scalav: String,
cli: Project,
testkit: Project,
testUtils: Project,
testsInput: Project,
testsInputMulti: MultiScalaProject,
testsOutput: Project,
testsOutputMulti: MultiScalaProject,
testsOutputDotty: Project,
testsShared: Project): Project = {
val unitMultiProject =
MultiScalaProject(
"unit",
s"scalafix-tests/unit",
_.settings(
noPublish,
fork := false,
javaOptions := Nil,
buildInfoPackage := "scalafix.tests",
buildInfoObject := "BuildInfo",
sources.in(Test) += baseDirectory
.in(ThisBuild)
.value / "scalafix-sbt" / "src" / "main" / "scala" / "scalafix" / "internal" / "sbt" / "ScalafixJarFetcher.scala",
libraryDependencies ++= coursierDeps ++ testsDeps
).enablePlugins(BuildInfoPlugin)
)
unitMultiProject(
scalav,
_.settings(
compileInputs.in(Compile, compile) := {
compileInputs
.in(Compile, compile)
.dependsOn(
compile.in(testsInput, Compile),
compile.in(testsOutputDotty, Compile),
compile.in(testsOutput, Compile)
)
.value
},
buildInfoKeys := Seq[BuildInfoKey](
"baseDirectory" ->
baseDirectory.in(ThisBuild).value,
"inputSourceroot" ->
baseDirectory.in(ThisBuild).value / testsInputMulti.srcMain,
"outputSourceroot" ->
baseDirectory.in(ThisBuild).value / testsOutputMulti.srcMain,
"testsInputResources" ->
baseDirectory
.in(ThisBuild)
.value / testsInputMulti.srcMain / "resources",
"outputDottySourceroot" ->
sourceDirectory.in(testsOutputDotty, Compile).value,
"semanticClasspath" ->
classDirectory.in(testsInput, Compile).value,
"sharedClasspath" ->
classDirectory.in(testsShared, Compile).value
)
).dependsOn(
testsInput,
cli,
testkit,
testUtils
)
)
}
lazy val unit211 = unit(
scala211,
cli211,
testkit211,
testUtils211,
testsInput211,
testsInput,
testsOutput211,
testsOutput,
testsOutputDotty,
testsShared211
)
lazy val unit212 = unit(
scala212,
cli212,
testkit212,
testUtils212,
testsInput212,
testsInput,
testsOutput212,
testsOutput,
testsOutputDotty,
testsShared212
)
lazy val website = project
.enablePlugins(MicrositesPlugin)
.enablePlugins(ScalaUnidocPlugin)
.settings(
scalaVersion := scala212,
noPublish,
websiteSettings,
unidocSettings,
libraryDependencies += "com.geirsson" %% "metaconfig-docs" % metaconfigV,
unidocProjectFilter in (ScalaUnidoc, unidoc) := inProjects(
testkit212,
core212JVM)
)
.dependsOn(testkit212, core212JVM, cli212)
.disablePlugins(ScalafixPlugin)
inScope(Global)(
Seq(
credentials ++= (for {
username <- sys.env.get("SONATYPE_USERNAME")
password <- sys.env.get("SONATYPE_PASSWORD")
} yield
Credentials(
"Sonatype Nexus Repository Manager",
"oss.sonatype.org",
username,
password)).toSeq,
PgpKeys.pgpPassphrase := sys.env.get("PGP_PASSPHRASE").map(_.toCharArray())
)
)