Skip to content

Commit

Permalink
Fix unused nowarn in sbt plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
adpi2 committed Apr 6, 2021
1 parent 7c266e8 commit 56746d5
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 2 deletions.
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

0 comments on commit 56746d5

Please sign in to comment.