Skip to content

Commit b2ede55

Browse files
authored
Build: Add unused imports check for scala code (#14344)
1 parent 911a486 commit b2ede55

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

baseline.gradle

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,22 @@ subprojects {
165165
quiet = false
166166
}
167167
}
168+
169+
pluginManager.withPlugin('scala') {
170+
String scalaVersion = System.getProperty("scalaVersion") != null ? System.getProperty("scalaVersion") : System.getProperty("defaultScalaVersion")
171+
tasks.withType(ScalaCompile).configureEach { scalaCompile ->
172+
if (scalaVersion?.startsWith("2.12")) {
173+
scalaCompile.scalaCompileOptions.additionalParameters = [
174+
// Scala 2.12 does not support treating unused imports as errors individually,
175+
// so we only enable warnings for unused imports when using Scala 2.12.
176+
"-Ywarn-unused:imports",
177+
]
178+
} else if (scalaVersion?.startsWith("2.13")) {
179+
scalaCompile.scalaCompileOptions.additionalParameters = [
180+
"-Wconf:cat=unused:error",
181+
"-Wunused:imports"
182+
]
183+
}
184+
}
185+
}
168186
}

0 commit comments

Comments
 (0)