scalaziomill

Why does running the ZIO App with mill not work?


I setup the simple ZIO App from zio.dev.

val myAppLogic =
    for {
      _    <- putStrLn("Hello! What is your name?")
      name <- getStrLn
      _    <- putStrLn(s"Hello, ${name}, welcome to ZIO!")
    } yield ()

When running in/with Intellij it works as expected.

However running it with mill it doesn't.

nbszmbp012:zio-scala-camunda-bot mpa$ mill server.run
[27/37] server.compile 
[info] Compiling 1 Scala source to /Users/mpa/dev/Github/pme123/zio-scala-camunda-bot/out/server/compile/dest/classes ...
[info] Done compiling.
[37/37] server.run 
Hello! What is your name?
Peter

name <- getStrLn is not executed.

Here is the build.sc

import mill._, scalalib._

object server extends ScalaModule {
  def scalaVersion = "2.12.8"
  def ivyDeps = Agg(
    ivy"dev.zio::zio:1.0.0-RC10-1",
    ivy"com.bot4s::telegram-core:4.3.0-RC1"
  )
}

Did I miss something?


Solution

  • Mill runs, by default, in client-server mode. One of the consequences is, that build tasks can't consume the input stream.

    Your given example needs to read from the process standard input. So, you have to explicitly tell mill to run in interactive mode with --interactive (or short -i).

    $ mill -i server.run
    [27/37] server.compile 
    [info] Compiling 1 Scala source to /tmp/zio-q/out/server/compile/dest/classes ...
    [info] Done compiling.
    [37/37] server.run 
    Hello! What is your name?
    Peter
    Hello, Peter, welcome to ZIO!
    

    When invoked with the additional -i (before the task name), the ZIO app correctly reads from STDIN and prints the greeting.