Search code examples
scalaplayframeworksbt

How to set custom console banner for Play application via SBT


When I run the command from terminal : sbt run

It logs on the console like this:

[info] welcome to sbt 1.3.13 (Azul Systems, Inc. Java 1.8.0_362)
[info] loading global plugins from /.sbt/1.0/plugins
[info] loading settings for project from plugins.sbt ...
[info] loading project definition from /demo/project
[info] loading settings for project root from build.sbt ...
[info]   __              __
[info]   \ \     ____   / /____ _ __  __
[info]    \ \   / __ \ / // __ `// / / /
[info]    / /  / /_/ // // /_/ // /_/ /
[info]   /_/  / .___//_/ \__,_/ \__, /
[info]       /_/               /____/
[info] 
[info] Version 2.8.18 running Java 1.8.0_362
[info] 
[info] Play is run entirely by the community. Please consider contributing and/or donating:
[info] https://www.playframework.com/sponsors

Now, I want to modify below default banner to a custom banner.

[info]   __              __
[info]   \ \     ____   / /____ _ __  __
[info]    \ \   / __ \ / // __ `// / / /
[info]    / /  / /_/ // // /_/ // /_/ /
[info]   /_/  / .___//_/ \__,_/ \__, /
[info]       /_/               /____/
[info] 

Is it even possible to modify? If yes, then please mention on how to do it.


Solution

  • Override onLoadMessage key in the build.sbt of your project:

    import play.sbt.Colors
    
    onLoadMessage := {
     """|  __              __
        |  \ \     ____   / /____ _ __  __
        |   \ \   / __ \ / // __ `// / / /
        |   / /  / /_/ // // /_/ // /_/ /
        |  /_/  / .___//_/ \__,_/ \__, /
        |      /_/               /____/
        |""".stripMargin.linesIterator.map(Colors.green(_)).mkString("\n")
    }
    

    If you want a custom banner for e.g. your contributors, personally I prefer to use sbt-welcome to provide users with some nice welcome message, useful tasks and hints how to start working with the code. It will set up onLoadMessage using some structured format.