I looked into this not too long ago here: Gradle Progect System.out.print("TEST") don't display on the console in IntelliJ
My conclusion was that there is a buffer somewhere between the IntelliJ output window and the Gradle tooling module. It only flushes on newlines (not even if on a call to .flush() on the stream will actually flush it).
It only happens in IntelliJ, so this is hopefully only a problem when debugging and not when actually using your application. It should work fine if you run your application directly with Java on the command line, or through Gradle without involving IntelliJ.