Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unused nowarn in sbt plugins #6431

Merged
merged 1 commit into from Apr 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 12 additions & 1 deletion main/src/main/scala/sbt/plugins/SbtPlugin.scala
Expand Up @@ -10,11 +10,22 @@ package plugins

import Keys._
import Def.Setting
import sbt.SlashSyntax0._
import sbt.librarymanagement.Configurations.Compile
import sbt.librarymanagement.{ SemanticSelector, VersionNumber }

object SbtPlugin extends AutoPlugin {
override def requires = ScriptedPlugin

override lazy val projectSettings: Seq[Setting[_]] = Seq(
sbtPlugin := true
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
}
)
}
1 change: 0 additions & 1 deletion sbt/src/sbt-test/actions/cross-multiproject/build.sbt
@@ -1,5 +1,4 @@
lazy val scala212 = "2.12.12"
// keep this at M5 to test full version
lazy val scala213 = "2.13.1"

ThisBuild / crossScalaVersions := Seq(scala212, scala213)
Expand Down
6 changes: 6 additions & 0 deletions sbt/src/sbt-test/project/sbt-plugin/build.sbt
@@ -0,0 +1,6 @@
lazy val root = project.in(file("."))
.enablePlugins(SbtPlugin)
.settings(
scalaVersion := "2.12.13",
scalacOptions ++= Seq("-Xfatal-warnings", "-Xlint")
)
@@ -0,0 +1,22 @@
package myplugin

import sbt._
import sbt.Keys._

case object MyPlugin extends AutoPlugin {
object autoImport {
val helloWorld = Def.taskKey[String]("log and return hello world")
}
import autoImport._
override def projectSettings: Seq[Def.Setting[_]] = Seq(
// should not produce a "@nowarn annotation does not suppres any warnings" warning
helloWorld := {
streams.value.log("Hello world")
"Hello world"
},
Compile / compile := {
helloWorld.value // shoult not produce "a pure expression does nothing" warning
(Compile / compile).value
}
)
}
1 change: 1 addition & 0 deletions sbt/src/sbt-test/project/sbt-plugin/test
@@ -0,0 +1 @@
> compile