Fix nowarn in both old & new sbt plugin styles

Fixes #6430.

What is the problem?
As detailed in #6430, the @nowarn annotation was not suppressing
warnings, even after the first attempt to fix this in PR#6431.

This first PR fixed the problem for projects using
enablePlugins(SbtPlugin), but not for those using sbtPlugin := true.

Why is this a valuable problem to solve?
The annotation was not working as users would expect.

What is this solution?
I have moved the scalacOptions change from SbtPlugin.projectSettings
to the scalacOptions in the JvmPlugin settings.

Has this been tested?
Yes, a test has been added. Also, this branch was tested successfully
on the twinagle repo (https://github.com/soundcloud/twinagle/pull/224).
This commit is contained in:
Amina Adewusi 2021-05-21 16:32:29 +01:00
parent 3ef1c5508b
commit 2e6fb3f2a5
4 changed files with 18 additions and 14 deletions

View File

@ -959,6 +959,13 @@ object Defaults extends BuildCommon {
Vector("-Ypickle-java", "-Ypickle-write", converter.toPath(earlyOutput.value).toString) ++ old
else old
},
scalacOptions := {
val old = scalacOptions.value
if (sbtPlugin.value && VersionNumber(scalaVersion.value)
.matchesSemVer(SemanticSelector("=2.12 >=2.12.13")))
old ++ Seq("-Wconf:cat=unused-nowarn:s")
else old
},
persistJarClasspath :== true,
classpathEntryDefinesClassVF := {
(if (persistJarClasspath.value) classpathDefinesClassCache.value

View File

@ -8,24 +8,13 @@
package sbt
package plugins
import Keys._
import Def.Setting
import sbt.SlashSyntax0._
import sbt.librarymanagement.Configurations.Compile
import sbt.librarymanagement.{ SemanticSelector, VersionNumber }
import sbt.Def.Setting
import sbt.Keys._
object SbtPlugin extends AutoPlugin {
override def requires = ScriptedPlugin
override lazy val projectSettings: Seq[Setting[_]] = Seq(
sbtPlugin := true,
Compile / scalacOptions ++= {
// silence unused @nowarns in 2.12 because of https://github.com/sbt/sbt/issues/6398
// the option is only available since 2.12.13
if (VersionNumber(scalaVersion.value).matchesSemVer(SemanticSelector("=2.12 >=2.12.13")))
Some("-Wconf:cat=unused-nowarn:s")
else
None
}
sbtPlugin := true
)
}

View File

@ -0,0 +1,6 @@
lazy val root = project.in(file("."))
.settings(
scalaVersion := "2.12.13",
sbtPlugin := true,
scalacOptions ++= Seq("-Xfatal-warnings", "-Xlint")
)

View File

@ -1 +1,3 @@
> compile
$ copy-file changes/oldSbtPlugin.sbt build.sbt
> compile