forked from scalacenter/scalafix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sbt
267 lines (248 loc) · 7.74 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
import Dependencies._
inThisBuild(
List(
onLoadMessage := s"Welcome to scalafix ${version.value}",
scalaVersion := scala212,
crossScalaVersions := List(scala212, scala211),
fork := true
)
)
cancelable.in(Global) := true
noPublish
// force javac to fork by setting javaHome to get error messages during compilation,
// see https://github.com/sbt/zinc/issues/520
def inferJavaHome() = {
val home = file(sys.props("java.home"))
val actualHome =
if (System.getProperty("java.version").startsWith("1.8")) home.getParentFile
else home
Some(actualHome)
}
lazy val interfaces = project
.in(file("scalafix-interfaces"))
.settings(
noMima,
resourceGenerators.in(Compile) += Def.task {
val props = new java.util.Properties()
props.put("scalafixVersion", version.value)
props.put("scalafixStableVersion", stableVersion.value)
props.put("scalametaVersion", scalametaV)
props.put("scala212", scala212)
props.put("scala211", scala211)
props.put("scala213", scala213)
val out =
managedResourceDirectories.in(Compile).value.head /
"scalafix-interfaces.properties"
IO.write(props, "Scalafix version constants", out)
List(out)
},
javacOptions.in(Compile) ++= List(
"-Xlint:all",
"-Werror"
),
javacOptions.in(Compile, doc) := List("-Xdoclint:none"),
javaHome.in(Compile) := inferJavaHome(),
javaHome.in(Compile, doc) := inferJavaHome(),
moduleName := "scalafix-interfaces",
crossVersion := CrossVersion.disabled,
crossScalaVersions := List(scala212),
autoScalaLibrary := false
)
lazy val core = project
.in(file("scalafix-core"))
.settings(
moduleName := "scalafix-core",
buildInfoSettings,
libraryDependencies ++= List(
scalameta,
googleDiff,
"com.geirsson" %% "metaconfig-typesafe-config" % metaconfigV,
"org.scala-lang" % "scala-reflect" % scalaVersion.value % Provided
)
)
.enablePlugins(BuildInfoPlugin)
lazy val rules = project
.in(file("scalafix-rules"))
.settings(
moduleName := "scalafix-rules",
description := "Built-in Scalafix rules",
libraryDependencies += "org.scalameta" % "semanticdb-scalac-core" % scalametaV cross CrossVersion.full
)
.dependsOn(core)
lazy val reflect = project
.in(file("scalafix-reflect"))
.settings(
moduleName := "scalafix-reflect",
isFullCrossVersion,
libraryDependencies ++= Seq(
"org.scala-lang" % "scala-compiler" % scalaVersion.value,
"org.scala-lang" % "scala-reflect" % scalaVersion.value
)
)
.dependsOn(core, rules)
lazy val cli = project
.in(file("scalafix-cli"))
.settings(
moduleName := "scalafix-cli",
isFullCrossVersion,
mainClass in assembly := Some("scalafix.v1.Main"),
assemblyJarName in assembly := "scalafix.jar",
libraryDependencies ++= Seq(
"org.scala-lang.modules" %% "scala-java8-compat" % "0.9.0",
"com.martiansoftware" % "nailgun-server" % "0.9.1",
jgit,
"ch.qos.logback" % "logback-classic" % "1.2.3",
"org.apache.commons" % "commons-text" % "1.8"
)
)
.dependsOn(reflect, interfaces)
lazy val testsShared = project
.in(file("scalafix-tests/shared"))
.settings(
semanticdbSettings,
noPublish,
coverageEnabled := false
)
val isScala213 = Def.setting(scalaVersion.value.startsWith("2.13"))
val warnAdaptedArgs = Def.setting {
if (isScala213.value) "-Xlint:adapted-args"
else "-Ywarn-adapted-args"
}
lazy val testsInput = project
.in(file("scalafix-tests/input"))
.settings(
noPublish,
semanticdbSettings,
scalacOptions ~= (_.filterNot(_ == "-Yno-adapted-args")),
scalacOptions += warnAdaptedArgs.value, // For NoAutoTupling
scalacOptions += warnUnusedImports.value, // For RemoveUnused
scalacOptions += "-Ywarn-unused", // For RemoveUnusedTerms
logLevel := Level.Error, // avoid flood of compiler warnings
libraryDependencies += "com.twitter" %% "bijection-core" % "0.9.6",
testsInputOutputSetting,
coverageEnabled := false
)
lazy val testsOutput = project
.in(file("scalafix-tests/output"))
.settings(
noPublish,
semanticdbSettings,
scalacOptions --= List(
warnUnusedImports.value,
"-Xlint"
),
testsInputOutputSetting,
coverageEnabled := false,
libraryDependencies += "com.twitter" %% "bijection-core" % "0.9.6"
)
lazy val testkit = project
.in(file("scalafix-testkit"))
.settings(
noMima,
moduleName := "scalafix-testkit",
isFullCrossVersion,
libraryDependencies ++= Seq(
semanticdb,
googleDiff,
scalacheck,
scalatest
)
)
.dependsOn(cli)
lazy val unit = project
.in(file("scalafix-tests/unit"))
.settings(
noPublish,
// Change working directory to match when `fork := false`.
baseDirectory.in(Test) := baseDirectory.in(ThisBuild).value,
javaOptions := Nil,
buildInfoPackage := "scalafix.tests",
buildInfoObject := "BuildInfo",
libraryDependencies ++= testsDeps,
libraryDependencies ++= List(
jgit,
semanticdbPluginLibrary,
scalatest,
"org.scalameta" %% "testkit" % scalametaV
),
compileInputs.in(Compile, compile) := {
compileInputs
.in(Compile, compile)
.dependsOn(
compile.in(testsInput, Compile),
compile.in(testsOutput, Compile)
)
.value
},
resourceGenerators.in(Test) += Def.task {
// copy-pasted code from ScalafixTestkitPlugin to avoid cyclic dependencies between build and sbt-scalafix.
val props = new java.util.Properties()
def put(key: String, files: Seq[File]): Unit = {
val value = files.iterator
.filter(_.exists())
.mkString(java.io.File.pathSeparator)
props.put(key, value)
}
put(
"inputClasspath",
fullClasspath.in(testsInput, Compile).value.map(_.data)
)
put(
"inputSourceDirectories",
sourceDirectories.in(testsInput, Compile).value
)
put(
"outputSourceDirectories",
sourceDirectories.in(testsOutput, Compile).value
)
props.put("scalaVersion", scalaVersion.value)
props.put("scalacOptions", scalacOptions.value.mkString("|"))
val out =
managedResourceDirectories.in(Test).value.head /
"scalafix-testkit.properties"
IO.write(props, "Input data for scalafix testkit", out)
List(out)
},
buildInfoKeys := Seq[BuildInfoKey](
"baseDirectory" ->
baseDirectory.in(ThisBuild).value,
"inputSourceroot" ->
sourceDirectory.in(testsInput, Compile).value,
"outputSourceroot" ->
sourceDirectory.in(testsOutput, Compile).value,
"unitResourceDirectory" -> resourceDirectory.in(Compile).value,
"testsInputResources" ->
sourceDirectory.in(testsInput, Compile).value / "resources",
"semanticClasspath" ->
classDirectory.in(testsInput, Compile).value,
"sharedSourceroot" ->
baseDirectory.in(ThisBuild).value /
"scalafix-tests" / "shared" / "src" / "main",
"sharedClasspath" ->
classDirectory.in(testsShared, Compile).value
)
)
.enablePlugins(BuildInfoPlugin)
.dependsOn(
testsInput,
testsShared,
cli,
testkit
)
lazy val docs = project
.in(file("scalafix-docs"))
.settings(
noMima,
baseDirectory.in(run) := baseDirectory.in(ThisBuild).value,
skip in publish := true,
moduleName := "scalafix-docs",
scalaVersion := scala212,
mdoc := run.in(Compile).evaluated,
crossScalaVersions := List(scala212),
libraryDependencies ++= List(
"com.geirsson" %% "metaconfig-docs" % metaconfigV,
"org.scalameta" % "semanticdb-scalac-core" % scalametaV cross CrossVersion.full
)
)
.dependsOn(testkit, core, cli)
.enablePlugins(DocusaurusPlugin)