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

[error] bad option: -P:silencer:checkUnused in Compile / doc #40

Open
solarmosaic-kflorence opened this issue Nov 14, 2019 · 7 comments

Comments

@solarmosaic-kflorence
Copy link

Just wanted to note that adding this flag to scalacOptions caused an error when trying to generate docs (sbt doc). To fix, I have removed this flag from Compile / doc scope in build.sbt like so:

scalacOptions in(Compile, doc) := scalacOptions.value.filterNot(Seq("-P:silencer:checkUnused").contains)

Although perhaps the flag could also only be applied to the Compile / compile scope:

scalacOptions in(Compile, compile) ++= Seq("-P:silencer:checkUnused")
@seglo
Copy link

seglo commented Jan 7, 2020

I ran into the same issue using another silencer parameter (pathFilter).

EDIT: my workaround

.settings(
  scalacOptions += "-P:silencer:pathFilters=src_managed",
  Compile / doc / scalacOptions := scalacOptions.value.filterNot(_.startsWith("-P:silencer"))
)

@ghik
Copy link
Owner

ghik commented Jan 8, 2020

Seems like sbt does not enable compiler plugins when generating documentation.
It should be easy to do that manually but currently I don't know exactly how to do it. Here's a SO question about that: https://stackoverflow.com/questions/59625041/how-to-enable-compiler-plugin-in-scaladoc.

Currently the best solution is to manually filter out plugin related compiler options when running doc, just like @solarmosaic-kflorence did.

@eed3si9n
Copy link

eed3si9n commented Jan 8, 2020

@ghik

Seems like sbt does not enable compiler plugins when generating documentation.

Is this true? I just called show utilLogging/Compile/doc/scalacOptions on the project that uses silencer and it include -Xplugin.

sbt:sbtRoot> show utilLogging/Compile/scalacOptions
[info] * -encoding
[info] * utf8
[info] * -deprecation
[info] * -feature
[info] * -unchecked
[info] * -Xlint
[info] * -language:higherKinds
[info] * -language:implicitConversions
[info] * -Xfuture
[info] * -Xlint
[info] * -Xfatal-warnings
[info] * -Yno-adapted-args
[info] * -Ywarn-dead-code
[info] * -Ywarn-numeric-widen
[info] * -Ywarn-value-discard
[info] * -Ywarn-unused-import
[info] * -Xplugin:/Users/eed3si9n/.coursier/cache/v1/https/repo1.maven.org/maven2/com/github/ghik/silencer-plugin_2.12/1.4.2/silencer-plugin_2.12-1.4.2.jar
[info] * -Ywarn-unused:-locals,-explicits,-privates
[success] Total time: 0 s, completed Jan 8, 2020 1:35:30 PM
sbt:sbtRoot> show utilLogging/Compile/doc/scalacOptions
[info] * -encoding
[info] * utf8
[info] * -deprecation
[info] * -feature
[info] * -unchecked
[info] * -Xlint
[info] * -language:higherKinds
[info] * -language:implicitConversions
[info] * -Xfuture
[info] * -Xlint
[info] * -Xfatal-warnings
[info] * -Yno-adapted-args
[info] * -Ywarn-dead-code
[info] * -Ywarn-numeric-widen
[info] * -Ywarn-value-discard
[info] * -Ywarn-unused-import
[info] * -Xplugin:/Users/eed3si9n/.coursier/cache/v1/https/repo1.maven.org/maven2/com/github/ghik/silencer-plugin_2.12/1.4.2/silencer-plugin_2.12-1.4.2.jar
[info] * -Ywarn-unused:-locals,-explicits,-privates
[info] * -sourcepath
[info] * /Users/eed3si9n/work/sbt-modules/sbt
[info] * -doc-source-url
[info] * https://github.com/sbt/sbt/tree/b37bad6644da01937fac6eabc798bc670742da24€{FILE_PATH}.scala
[success] Total time: 0 s, completed Jan 8, 2020 1:35:36 PM

@eed3si9n
Copy link

eed3si9n commented Jan 8, 2020

And here's wtih Compile / scalacOptions ++= Seq("-P:silencer:checkUnused")

sbt:sbtRoot> show utilLogging/Compile/scalacOptions
[info] * -encoding
[info] * utf8
[info] * -deprecation
[info] * -feature
[info] * -unchecked
[info] * -Xlint
[info] * -language:higherKinds
[info] * -language:implicitConversions
[info] * -Xfuture
[info] * -Xlint
[info] * -Xfatal-warnings
[info] * -Yno-adapted-args
[info] * -Ywarn-dead-code
[info] * -Ywarn-numeric-widen
[info] * -Ywarn-value-discard
[info] * -Ywarn-unused-import
[info] * -Xplugin:/Users/eed3si9n/.coursier/cache/v1/https/repo1.maven.org/maven2/com/github/ghik/silencer-plugin_2.12/1.4.2/silencer-plugin_2.12-1.4.2.jar
[info] * -Ywarn-unused:-locals,-explicits,-privates
[info] * -P:silencer:checkUnused
[success] Total time: 0 s, completed Jan 8, 2020 1:57:48 PM
sbt:sbtRoot> show utilLogging/Compile/doc/scalacOptions
[info] * -encoding
[info] * utf8
[info] * -deprecation
[info] * -feature
[info] * -unchecked
[info] * -Xlint
[info] * -language:higherKinds
[info] * -language:implicitConversions
[info] * -Xfuture
[info] * -Xlint
[info] * -Xfatal-warnings
[info] * -Yno-adapted-args
[info] * -Ywarn-dead-code
[info] * -Ywarn-numeric-widen
[info] * -Ywarn-value-discard
[info] * -Ywarn-unused-import
[info] * -Xplugin:/Users/eed3si9n/.coursier/cache/v1/https/repo1.maven.org/maven2/com/github/ghik/silencer-plugin_2.12/1.4.2/silencer-plugin_2.12-1.4.2.jar
[info] * -Ywarn-unused:-locals,-explicits,-privates
[info] * -P:silencer:checkUnused
[info] * -sourcepath
[info] * /Users/eed3si9n/work/sbt-modules/sbt
[info] * -doc-source-url
[info] * https://github.com/sbt/sbt/tree/b37bad6644da01937fac6eabc798bc670742da24€{FILE_PATH}.scala
[success] Total time: 0 s, completed Jan 8, 2020 1:57:51 PM

@ghik
Copy link
Owner

ghik commented Jan 9, 2020

Thanks @eed3si9n, that's interesting. Then it seems that silencer was somehow not properly enabled for doc in projects of @solarmosaic-kflorence and @seglo - can you please share your build.sbt or an example project?

@seglo
Copy link

seglo commented Jan 9, 2020

@ghik The project I'm working with is https://github.com/akka/alpakka. The solution @eed3si9n proposed by omitting the intask component when defining the scope on scalacOptions seems to work, but I had already merged my workaround.

And here's wtih Compile / scalacOptions ++= Seq("-P:silencer:checkUnused")

Before the workaround (akka/alpakka#2077) the build would fail during our snapshot publishing step, on the doc task.

sbt ";++2.13.1;google-cloud-pub-sub-grpc / Compile / doc"

@solarmosaic-kflorence
Copy link
Author

I believe my build.sbt conforms exactly to how the plugin is documented in the readme.md:

object Dependencies {
  val silencerLib = "com.github.ghik" % "silencer-lib" % Versions.Silencer % Provided
  val silencerPlugin = "com.github.ghik" % "silencer-plugin" % Versions.Silencer
}

object Versions {
  val Silencer = "1.4.4"
}

lazy val foo = (project in file("foo"))
  .settings(
    libraryDependencies ++= Seq(
        compilerPlugin(Dependencies.silencerPlugin).cross(CrossVersion.full),
        Dependencies.silencerLib.cross(CrossVersion.full)
    ),
    scalacOptions ++= Seq(
      "-P:silencer:checkUnused",
      ...
    )
  )

So is another fix to use Compile / scalacOptions += "-P:silencer:checkUnused" instead? If so perhaps it should also be documented that way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants