How can I print a series of dots horizontally during a long task

(luis) #1

I have implemented some deployment tasks on AWS that can run for a fairly long time. I have been using println which I read is mapped to to log information as these tasks run and print ‘.’ to print out some dots when the task is waiting for some condition to occur. This works fine except the dots aren’t actually printed out until the next println which is unfortunate since the idea is to provide some feedback that the task is actually running and not stuck in limbo. Is there a way to accomplish this without using println ‘.’ which would be an ok last resort but would look awkward in the output.


(Luke Daley) #2

There’s no really convenient way to do this at the moment. I’ve raised GRADLE-2787 for this.

In the meantime, you can use our progress logging API. It’s a bit awkward, and there are no docs (besides Javadoc).

Here’s some example usage:

(luis) #3

Awesome, thank you for the super quick reply! I will try this out.


(Sion Williams) #4

Depending on your implementation, the snippet from the Groovy in Action book may be useful.

See below:

def processFiles(notify) {
  def names = new File('.').list()
  names.eachWithIndex { name, i ->
   notify(i * 10 / names.size(), name)
   sleep 50
 processFiles { filled, info ->
  print '\b' * 61
  print '#'*filled + ':'*(10-filled) +' '+ info.padRight(50)

(luis) #5

@Sion Thanks ! I tried that out your code snippet but saw some weird backspace effects, wasn’t exactly what I’m looking for.


I fittted a ProgressLogger instance in the same way as in the CompareGradleBuilds task into my waitUntil method as follow but I can’t see the output. I tried running with the --info flag to no avail so I must be missing something.

void waitUntil(String message, Closure condition) {

println message

if (processLogger) processLogger.started message

boolean done

while (!done) {

done = condition()

if (!done) {

sleep 5000

if (processLogger) {

processLogger.progress ‘.’

} else {

print ‘.’


} else {

println ‘’





(Luke Daley) #6

The progress logger output is not incremental. You’ll need to collect up the dots and log the whole string each time.