Detecting gradle color settings

I know that some questions have been asked about how to hook into gradle’s color output – but I have not yet seen a question/answer about how to simply detect gradle’s color settings.

I have a test listener that outputs test results more concisely than the built in gradle test events do (it was originally a test listener for testng). I’m trying to get this listener to hook into gradle’s “–no-color” option rather than inventing a new -Dcolor=false system property to turn off color.

Is there a way to do this? Thanks.

I don’t understand the question. Are you trying to disable colors for parts of the output? Not sure that’s possible. And how is this related to your listener?

Sorry for not being clear…

I’m trying to detect whether gradle itself is in “color” or “–no-color” mode or not, so that I can adjust my custom test listener to use color or not based on gradle’s color setting.

You can detect whether ‘–no-color’ was passed via ‘gradle.startParameter.isColorOutput()’. However, I’m not aware of a public API to determine whether Gradle considers the current terminal to be capable of displaying colors.

Awesome. ‘gradle.startParameter.isColorOutput()’ is exactly what I was looking for. Thanks.

How can I set gradle.startParameter.isColorOutput() I want to print PASSED: 1 in GREEN and FAILED: 0 in Red, ERRORs: 0 in Organge

‘gradle.startParameter.colorOutput’ turns colors on or off. I’m not aware of a way to configure which colors to use.

This reply was created from a merged topic originally titled I would like to print out the color in the gradle gui output. I’d like to print PASS in Green color and FAIL in Red color and ERROR in Orang.