Suppressing 3rd party output in a task

(Jeff Titmas) #1

I have a task which calls an external library in order to run some jobs. There are 3 parts to the task:

  • setting up the jobs
  • executing the jobs - this calls the external library
  • reviewing the results

I would like to be able to control the output from my task - what appears on the screen or goes to a log file.

However the external library I am calling is producing a lot of noise - various warning/error messages produced by the jobs - which I do not want to appear in the task output. I am not sure whether these messages are written to standard error or standard output.

Am I able to suppress the standard output/error from within my task?

A simplified version of my task code is:

import org.gradle.api.DefaultTask
import org.gradle.api.tasks.TaskAction

import <external library>

class myTask extends DefaultTask {

    def taskAction() {

        // Task setup - this should not be filtered
        println "Starting task execution..."
        def params = ...

        // This call generates a lot of noise which I 
        // don't want in the logs or on the screen
        def result = <call to the external library> ... (params...)

        // Task completion - this should not be filtered
        if (result == "PASS") {
            println "Completed task execution..."