Scala sbt: How to turn off [info] messages for `~run`? - scala

When using ~run I don't want to see [info] messages.
I have tried sbt -error and set logLevel := Level.Error but the [info] messages are still emitted.
This question is similar to How to suppress info and success messages in sbt?. However the solution there works only for sbt run whereas this question is about ~run issued after starting sbt in interactive mode (sbt -error).

Related

Using sbt run on simple tutorial example does not execute

On a Windows machine, I am running through the getting started tutorial here: https://www.scala-sbt.org/1.x/docs/sbt-by-example.html
I am able to start the sbt shell and compile but using the run command just hangs and I am forced to Ctrl-C to exit sbt.
Running scala against the JAR file directly also works as expected.
Sample output is the following:
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0
[info] Loading project definition from S:\foo-build\project
[info] Loading settings for project foo-build from build.sbt ...
[info] Set current project to foo-build (in build file:/S:/foo-build/)
[info] sbt server started at local:sbt-server-8c6933abcb6848dbd242
sbt:foo-build> about
[info] This is sbt 1.2.8
[info] The current project is ProjectRef(uri("file:/S:/foo-build/"), "foo-build") 0.1.0-SNAPSHOT
[info] The current project is built against Scala 2.12.7
[info] Available Plugins
[info] - sbt.ScriptedPlugin
[info] - sbt.plugins.CorePlugin
[info] - sbt.plugins.Giter8TemplatePlugin
[info] - sbt.plugins.IvyPlugin
[info] - sbt.plugins.JUnitXmlReportPlugin
[info] - sbt.plugins.JvmPlugin
[info] - sbt.plugins.SbtPlugin
[info] sbt, sbt plugins, and build definitions are using Scala 2.12.7
sbt:foo-build> compile
[success] Total time: 0 s, completed Feb 7, 2019 4:40:45 PM
sbt:foo-build> run
Terminate batch job (Y/N)? Y
This is enough of an answer for my own purposes.
I was able work around this issue by adding a line to my build.sbt file. After adding ThisBuild / scalaVersion := "2.12.8" I was able to use the run command. Following the tutorial linked in the main question I would not expect to have to do this but perhaps someone could shed some light.

Scala 2.12 logging compilation too verbosely in SBT 0.13.16

Since updating to Scala 2.12, sbt logs immense amounts at info level on compilation, e.g.:
[info] /home/zoltan/workspace/reboot/juniqe/libs/db/src/main/scala/com/juniqe/db/slick/CmsBlockDao.scala:548: isomorphicType is not a valid implicit value for slick.ast.TypedType[slick.lifted.Rep[Short]] because:
[info] hasMatchingSymbol reported error: could not find implicit value for parameter iso: slick.lifted.Isomorphism[slick.lifted.Rep[Short],B]
[info] block <- CmsBlock if block.blockId === blockId
[info] ^
This looks like an error, but there is no compilation error, so I would like to silence these messages, because sometimes there's so many of them, my terminal overflows and I can't see the actual compilation errors.
How can I lower the logging level just for compilation (including test and integration test compilation)?
I've tried setting logLevel in Compile := Level.Warn, and logLevel in Compile := Level.Warn, but the messages are still there.
Setting logLevel in Global := Level.Warn does the trick, but I don't want to set it for the Global scope.
Note: This is a multi-project build, and I'm running compile from the root project.
Well, turns out that all these errors appeared because a colleague had enabled the SBT flag -Xlog-implicits, which, according to SBT "Show[s] more info on why some implicits are not applicable". After removing this flag, the errors were gone.
Source: https://paulbutcher.com/2010/04/26/scala-compiler-advanced-options/

How do I run sbt quietly? [duplicate]

When I do sbt run I see some header and footer info which I would like to get rid of:
$ sbt run
[info] Set current project to XXX (in build file:/path/to/dir/)
<actual program output goes here; stuff I care about>
[success] Total time: 68 s, completed Apr 1, 2012 7:30:45 PM
$
How can I get rid of those 2 additional lines (i.e., the [info] and [success] lines)? Are there some build.sbt configuration settings available to do that? Ideally, I don't want to have another tool/dependency just to get rid of those 2 lines.
Following is a list of things I have tried:
Set run logLevel to Warn
Set Global logLevel to Warn
Set -Dsbt.log.noformat=true
The workaround that I am currently using:
Copy the java invocation that sbt generates (by doing ps or top) as a result of doing fork in run := true and manually run that java command directly on the command line.
It would be much cleaner if sbt could be told not to print those lines.
Scala version: 2.9.1
SBT version: 0.11.1
sbt 1.x, sbt 0.13.13+
Use -warn or -error. See Fixes with compatibility implications for sbt 0.13.13 release:
it is strongly encouraged to migrate to the single hyphen options: -error, -warn, -info, and -debug
sbt 0.13.1
To disable info messages run SBT with --warn or --error command line options.
To disable [success] messages set showSuccess to false.
Bringing it all together, it gives you the following options:
On command line use the following:
$ sbt --error 'set showSuccess := false' run
In build.sbt add showSuccess := false
$ cat build.sbt
showSuccess := false
and execute sbt --error run.
As Jacek mentioned in his response, in build.sbt you can add showSuccess := false to suppress the [success] message. To suppress the [info] message, I'd set the logLevel to Level.Warn for the run configuration only. Putting it together, you want to add these lines to build.sbt:
showSuccess := false
logLevel in run := Level.Warn
You should be able to get rid of the "Set current project" line by adding this to your build.sbt file:
onLoadMessage := ""
This is an old question that comes up at top of web searches, but gives the wrong answer. After this change was recently merged, the prescribed way to suppress interactive noise is by passing two flags to sbt:
sbt -batch -error ...
Works for me in sbt 1.8.0

How to find out which dependency caused a particular library to be downloaded?

When runing my SBT project, there is a line in console output:
[info] downloading http://repository/nexus/content/groups/public/org/jboss/netty/netty/3.2.3.Final/netty-3.2.3.Final.jar ...
[info] [SUCCESSFUL ] org.jboss.netty#netty;3.2.3.Final!netty.jar(bundle) (651ms)
How to find out which project dependency caused the netty.jar to be downloaded?
This plugin should be able to help: https://github.com/jrudolph/sbt-dependency-graph/
Another way would be to turn on full debug in your build.sbt as follows:
ivyLoggingLevel := UpdateLogging.Full
logLevel := Level.Debug
and then you could parse the output of sbt update
For example, If I wanted to know where logback-core comes from in my sample project, I could run
sbt update | grep logback-core
And I would get multiple such lines, telling me that it comes with logback-classic:
[debug] == resolving dependencies ch.qos.logback#logback-classic;1.0.10->ch.qos.logback#logback-core;1.0.10 [compile->master(*)]

How to suppress info and success messages in sbt?

When I do sbt run I see some header and footer info which I would like to get rid of:
$ sbt run
[info] Set current project to XXX (in build file:/path/to/dir/)
<actual program output goes here; stuff I care about>
[success] Total time: 68 s, completed Apr 1, 2012 7:30:45 PM
$
How can I get rid of those 2 additional lines (i.e., the [info] and [success] lines)? Are there some build.sbt configuration settings available to do that? Ideally, I don't want to have another tool/dependency just to get rid of those 2 lines.
Following is a list of things I have tried:
Set run logLevel to Warn
Set Global logLevel to Warn
Set -Dsbt.log.noformat=true
The workaround that I am currently using:
Copy the java invocation that sbt generates (by doing ps or top) as a result of doing fork in run := true and manually run that java command directly on the command line.
It would be much cleaner if sbt could be told not to print those lines.
Scala version: 2.9.1
SBT version: 0.11.1
sbt 1.x, sbt 0.13.13+
Use -warn or -error. See Fixes with compatibility implications for sbt 0.13.13 release:
it is strongly encouraged to migrate to the single hyphen options: -error, -warn, -info, and -debug
sbt 0.13.1
To disable info messages run SBT with --warn or --error command line options.
To disable [success] messages set showSuccess to false.
Bringing it all together, it gives you the following options:
On command line use the following:
$ sbt --error 'set showSuccess := false' run
In build.sbt add showSuccess := false
$ cat build.sbt
showSuccess := false
and execute sbt --error run.
As Jacek mentioned in his response, in build.sbt you can add showSuccess := false to suppress the [success] message. To suppress the [info] message, I'd set the logLevel to Level.Warn for the run configuration only. Putting it together, you want to add these lines to build.sbt:
showSuccess := false
logLevel in run := Level.Warn
You should be able to get rid of the "Set current project" line by adding this to your build.sbt file:
onLoadMessage := ""
This is an old question that comes up at top of web searches, but gives the wrong answer. After this change was recently merged, the prescribed way to suppress interactive noise is by passing two flags to sbt:
sbt -batch -error ...
Works for me in sbt 1.8.0