如何让 SBT 不报告生成代码的编译警告? [英] How to make SBT not reporting compilation warnings for generated code?
问题描述
我使用 scalaxb-sbt 插件生成代码,该插件在编译时会生成大量警告消息.有没有办法隐藏生成的代码或包的编译警告?
I generate code with the scalaxb-sbt plugin that, when compiled, generates a good number of warning messages. Is there any way to hide compilation warnings for generated code or by package?
推荐答案
对于 Scala 2.12.13+ 或 2.13.2+
Scala 编译器的最新版本集成了消音器插件,参见 可配置警告.
所以现在你不需要任何插件,只需在 build.sbt
中添加以下行:
ThisBuild / scalacOptions += "-Wconf:src=src_managed/.*:silent"
使用此选项将禁止对位于源代码树中任意位置的 src_managed
目录下的生成代码发出警告.
Using this option will suppress warnings for generated code that lives under a directory called src_managed
anywhere in your source tree.
这解决了我用 zio-grpc
生成的代码的问题,其中编译器发出警告,如 parameter value evidence$3 in method live is never used
(仅添加此信息以获得更好的可搜索性).
This solved my problem with code generated by zio-grpc
, where the compiler emitted warnings like parameter value evidence$3 in method live is never used
(adding this info only for better searchability).
这篇关于如何让 SBT 不报告生成代码的编译警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!