# Gradle print vs println

**URL:** <https://discuss.gradle.org/t/gradle-print-vs-println/21334>\
**Category:** Help/Discuss\
**Created:** [January 25, 2017, 2:27pm UTC](https://discuss.gradle.org/t/gradle-print-vs-println/21334 "2017-01-25T14:27:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Abrasha](https://avatars.discourse-cdn.com/v4/letter/a/e47774/32.png) [@Abrasha](https://discuss.gradle.org/u/Abrasha)\
**Post date:** [January 25, 2017, 2:27pm UTC](https://discuss.gradle.org/t/gradle-print-vs-println/21334/1 "2017-01-25T14:27:31Z")

</div>

I understand the difference between `print` and `println` methods.  
But why Gradle with default logging level prints output with `println` but doesn’t with `print` or `printf`?

_TaskProgress.groovy_

```
public class TaskProgress {

    private static final String PROGRESS_SYMBOLS = '_/\\_';
    private static final int MAX_POINTS = PROGRESS_SYMBOLS.length() - 2

    AtomicBoolean inProgress = new AtomicBoolean(true)
    int currentChar = 0
    int delta = 1

    private TaskProgress() {}

    static TaskProgress doProgress() {
        Log.error("START PROGRESS")
        def taskProgress = new TaskProgress();
        taskProgress.startProgress()
        return taskProgress
    }

    private void startProgress() {
        Thread.start {
            Log.error('STARTING:')
            while (inProgress.get()) {
                if (currentChar > MAX_POINTS) {
                    delta = -1
                } else if (currentChar == 0) {
                    delta = 1
                }
                println PROGRESS_SYMBOLS[currentChar] // it works
                print PROGRESS_SYMBOLS[currentChar] // it doesn't work
                currentChar += delta
                if (!inProgress.get()) break;
            }
            Log.error('STOPPING:')
        }
    }

    public void stopProgress() {
        Log.error("STOP PROGRESS")
        inProgress.set(false)
    }

}

```

_buid.gradle_

```
task progress {
    doLast {
        def progress = TaskProgress.doProgress()
        Thread.sleep(1000)
        progress.stopProgress()
    }
}

```

* * *

Or even simplier example:

```
task example1 {
    doLast {
        Thread.start {
            print 10
        }
    }
}

task example2 {
    doLast {
        Thread.start {
            println 20
        }
    }
}

```

Just call `./gradlew example1 example2` and see that output is:

> :example1  
> :example2  
> 20

When I use `print` in the main thread it works okay. Is it a defect?

---

<div class="post-metadata">

**Author:** ![thokari](https://avatars.discourse-cdn.com/v4/letter/t/b5e925/32.png) [@thokari](https://discuss.gradle.org/u/thokari)\
**Post date:** [November 8, 2017, 12:46pm UTC](https://discuss.gradle.org/t/gradle-print-vs-println/21334/2 "2017-11-08T12:46:56Z")

</div>

I am not sure what causes this behaviour, but I could make your example work by calling

`System.out.flush()`

after the call to `print`.

---

<div class="post-metadata">

**Author:** ![nanoPop12](https://avatars.discourse-cdn.com/v4/letter/n/47e85d/32.png) [@nanoPop12](https://discuss.gradle.org/u/nanoPop12)\
**Post date:** [July 21, 2020, 3:41am UTC](https://discuss.gradle.org/t/gradle-print-vs-println/21334/3 "2020-07-21T03:41:41Z")

</div>

Bringing this up to attention.

Currently, whether in IntelliJ IDEA or Netbeans, both only flush when there is a newline character.

System.out.printf(“xyz\n”);  
or  
System.out.println(“xyz”);

These two above works. These two below however, do not work until there is another \n

System.out.print(“xyz”);  
System.out.printf(“xyz”);

This makes it impossible to obtain user input at the same line due to the fact that System.out.flush() does not work either.
