Gradle Progect System.out.print("TEST") don't display on the console in IntelliJ

I create a Gradle project, an type this code as below, but no display on the console. Please help me, thanks.

public static void main(String[] args) {

    new Thread(new Runnable() {

        public void run() {
            while(true) {
                try {
                } catch (InterruptedException e) {

This is my test code.

This is about the problem.

System.out is generally a buffered stream, and won’t flush until it either encounters a newline character ("\n") or you use one of the println methods or you flush it yourself with .flush().

That being said, I tried your example in IntelliJ. Using either println or the newline character caused the output to be flushed as I predicted, but using .flush() didn’t. So I tried using the Gradle application plugin and running it from the terminal using “gradle run”. And here the string was printed immediately without even requiring a flush. But running the application from IntelliJ using the same “run” task again didn’t show anything in the terminal immediately. So I expect that there is another buffer with the same behaviour somewhere, maybe in the Gradle Tooling API or in the way IntelliJ uses it.

In any case, can’t you just end the output with a newline? :slight_smile:

1 Like