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

@nowarn annotation does not suppress any warnings when compiling SBT plugins #6430

Closed
dziemba opened this issue Apr 6, 2021 · 5 comments · Fixed by #6431 or #6517
Closed

@nowarn annotation does not suppress any warnings when compiling SBT plugins #6430

dziemba opened this issue Apr 6, 2021 · 5 comments · Fixed by #6431 or #6517

Comments

@dziemba
Copy link

dziemba commented Apr 6, 2021

steps

Trying to build an SBT plugin with sbt 1.5.0, in our case twinagle.

problem

We get @nowarn annotation does not suppress any warnings errors in the code that extends AutoPlugin.

expectation

No warnings/errors are emitted.

notes

Seems related to #6398

@adpi2
Copy link
Member

adpi2 commented Apr 6, 2021

Thanks for reporting!

This bug is indeed related to #6398

We will be able to fix it by adding scalacOptions += "-Wconf:cat=unused-nowarn:s" to the SbtPlugin.projectSettings

As a temporary fix you should do the same in your build.

@dziemba
Copy link
Author

dziemba commented Apr 7, 2021

Thanks for the quick fix!

@dziemba
Copy link
Author

dziemba commented Apr 26, 2021

Hey @adpi2 and @eed3si9n, it looks like the problem still happens with sbt 1.5.1, at least under certain circumstances. Here's a minimal example:

$ cat build.sbt
sbtPlugin := true
scalacOptions ++= Seq("-Xlint", "-Xfatal-warnings")

$ cat project/build.properties
sbt.version=1.5.1

$ cat src/main/scala/Test.scala
import sbt.Keys._
import sbt._

object Test extends AutoPlugin {
  override def projectSettings: Seq[Setting[_]] = Seq(organization := "foo")
}

$ sbt compile
[info] welcome to sbt 1.5.1 (AdoptOpenJDK Java 1.8.0_282)
[info] loading project definition from ~/tmp/project
[info] loading settings for project tmp from build.sbt ...
[info] set current project to tmp (in build file:~/tmp/)
[info] Executing in batch mode. For better performance use sbt's shell
[info] compiling 1 Scala source to ~/tmp/target/scala-2.12/sbt-1.0/classes ...
[error] ~/tmp/src/main/scala/Test.scala:5:68: @nowarn annotation does not suppress any warnings
[error]   override def projectSettings: Seq[Setting[_]] = Seq(organization := "foo")
[error]                                                                    ^
[error] one error found
[error] (Compile / compileIncremental) Compilation failed

@dziemba
Copy link
Author

dziemba commented May 4, 2021

Ah, I think I figured this out. Looking at the fix (https://github.com/sbt/sbt/pull/6431/files) it only works when using enablePlugins(SbtPlugin) instead of sbtPlugin := true.

I assume that using the plugin is (now) preferred over just setting the sbtPlugin key?

@eed3si9n
Copy link
Member

eed3si9n commented May 5, 2021

@dziemba Thanks for the detective work. It's true that using SbtPlugin is generally preferred but I am not sure if it's ok to start displaying false warnings without it. A quick fix might be to move the fix into a regular JvmPlugin settings.

Nirvikalpa108 pushed a commit to Nirvikalpa108/sbt that referenced this issue May 21, 2021
Fixes sbt#6430.

What is the problem?
As detailed in sbt#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 (soundcloud/twinagle#224).
Nirvikalpa108 pushed a commit to Nirvikalpa108/sbt that referenced this issue May 21, 2021
Fixes sbt#6430.

What is the problem?
As detailed in sbt#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 (soundcloud/twinagle#224).
Nirvikalpa108 pushed a commit to Nirvikalpa108/sbt that referenced this issue Oct 30, 2021
Fixes sbt#6430.

What is the problem?
As detailed in sbt#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 (soundcloud/twinagle#224).
Nirvikalpa108 pushed a commit to Nirvikalpa108/sbt that referenced this issue Oct 30, 2021
Fixes sbt#6430.

What is the problem?
As detailed in sbt#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 (soundcloud/twinagle#224).
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.