gradle: how to suppress "* What went wrong:", "* Try:" messages

Viewed 162

Gradle shows "* What went wrong:", "* Try:" messages every failed testing.

$ gradle test -q

2 tests completed, 1 failed

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':test'.
> There were failing tests. See the report at: file:///home/gradle/app/build/reports/tests/test/index.html

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

I want to show only:

2 tests completed, 1 failed

FAILURE: Build failed with an exception.

How can I suppress this hint messages?

1 Answers

I ended up following Gradle's guide on creating custom event logger

I created this file customlogger.gradle.kts

useLogger(CustomEventLogger())

class CustomEventLogger() : BuildAdapter(), TaskExecutionListener {
    override fun beforeExecute(task: Task) { }
    override fun afterExecute(task: Task, state: TaskState) { }
    override fun buildFinished(result: BuildResult) {
        if (result.failure != null) {
            println("Build completed with errors".red)
        } else {
            println("Build completed".green)
        }
    }

    val String.red: String get() { return "\u001b[31m$this\u001b[0m" }
    val String.green: String get() { return "\u001b[32m$this\u001b[0m" }
}

then I run:

supervisor -n exit -x gradle -- -I ./customlogger.gradle.kts test

Everything is as clean as it should be now (except for that last line. ugh)

enter image description here

Related