How can I prevent Gradle's stdout intervention?

(Blaine Simpson) #1

I want to convert my special-purpose Bash unit testing script to Groovy, and I want to use Gradle’s excellent wrapper system to eliminate the need for users to install Groovy. I can do everything I want, except that when I invoke Groovy from my Gradle build script, Gradle writes an extra space character after each backspace character that I write. This works perfectly when invoked directly with Groovy:

class Hg {

public static doit() {

println ‘Doing it’

for (i in 1…10) {

print ‘-’



print ‘\b+’





} }


If you can’t tell by the code, it prints a line of hypens, and as each test succeeds, it backspaces and changes the - to a +, so that when it’s finished the screen shows: ++++++++++

I have tried the following things, and none have any effect: * use System.out directly instead of prints * use Gradle’s --no-color switch * write the \b separately, with flush after it * coerce the \b to a character (in case something’s converting it into a String

(Blaine Simpson) #2


Use System.console().writer() to do all prints, printlns, and flushes.

Tested successfully from MSYS Bash shell and Windows CMD shell.

(Matias Bjarland) #3

Also verified working on OSX 10.7.2.

Two things worth noting:

  1. System.console() currently returns null if you are running gradle with the “–daemon” flag as daemon processes in java do not have a console. The gradle team has stated that this will be addressed in the 1.0 release time frame.

  2. System.console() is a java 6 feature. If you or your users are running older versions, this solution would not work.

(Blaine Simpson) #4

Thanks. Re. your #1, I see that it’s also incompatible… along with many other Gradle capabilities… with the --gui switch.

Constraints happen to be marginally acceptable for my current need. Hopefully won’t have people who need a Gui running my unit tests, and it’s ok to require Java6 for these folk. Would be a different situation if this was for a general audience. My test runner works as good and fast (and looks as good) as it did in Bash.