Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make SBT not reporting compilation warnings for generated code?

Tags:

scala

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?

like image 455
sortega Avatar asked Mar 28 '14 20:03

sortega


4 Answers

For Scala 2.12.13+ or 2.13.2+

Recent versions of the Scala compiler integrate the silencer plugin, see configurable warnings.
So now you don't need any plugin, just add the following line to build.sbt:

ThisBuild / scalacOptions += "-Wconf:src=src_managed/.*:silent"

Using this option will suppress warnings for generated code that lives under a directory called src_managed anywhere in your source tree.

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).

like image 168
zagyi Avatar answered Nov 15 '22 21:11

zagyi


I found that I needed to do set logLevel in Compile := Level.Error in my sbt console session in order for this to work. This is with a capital C in Compile. This is with sbt version 0.13.11. This is also to turn all warnings off, though.

like image 28
Mark Eibes Avatar answered Nov 15 '22 21:11

Mark Eibes


The silencer compiler plugin allows to suppress compiler warnings. It supports filtering out files by path. This will filter out all generated files from warnings:

scalacOptions += "-P:silencer:pathFilters=src_managed"
like image 44
dvim Avatar answered Nov 15 '22 21:11

dvim


In your sbt console you could try the following: set logLevel in compile := Level.Error or eventually set logLevel in sourceGenerators := Level.Error and experiment with different settings. Once you are happy you could apply this setting in your build.sbt.

More detailed information can be found in the sbt documentation: http://www.scala-sbt.org/release/docs/Howto/logging.html

like image 41
Markus Avatar answered Nov 15 '22 22:11

Markus