Colorful Gradle
Did you ever whished to change the color of your gradle log output? Maybe to highlight something?
AFAIK, Gradle has no support for colors out of the box, but you can solve this easily - even without an additional library.
The key to success are ANSI escape sequences (which are supported by most terminals) and a little trick.
The excape squences are initiated with the ESC-character 27.
To print this character from within Java or Groovy, you need to cast it a little bit like this new String((char) 27)
.
And that’s already all of the magic, because the rest of the escape sequences are standard ASCII characters.
So, print new String((char) 27) + "[33m"
turns the rest of your text yellow and print new String((char) 27) + "[0m"
returns to the default color of the console.
Now, let’s turn this knowledge into a small closure
With this closure, you can now spice up your text with color like this:
The result looks something like this: