Open solarmosaic-kflorence opened 4 years ago
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"))
)
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.
@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
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
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?
@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 (https://github.com/akka/alpakka/pull/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"
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.
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 fromCompile / doc
scope inbuild.sbt
like so:Although perhaps the flag could also only be applied to the
Compile / compile
scope: