Possibility to clear screen before continous build output?

Hi All,
I really like the “gradle build -t” option to immediately see if unit-tests are failing.
Is there are way to tell gradle to clear the screen when it detects a change an runs the build? This would make it much easier for the eye to see what is going on as it would always be on the top of the terminal window instead of adding content at the end.

I hope it is understandable what i want: I don’t want to see the output of the previous runs in the terminal window; only always the latest run.

Thanks,
Daniel

It is possible for you to add a listener that will run a command to clear the screen. For example:

gradle.addListener new BuildAdapter() {
    void projectsEvaluated(Gradle gradle) {
        exec { commandLine 'clear' }
    }
}

The choice of projectsEvaluated is pretty arbitrary, but it is called on each triggered run and occurs relatively early in the process.

1 Like

the solution works great. as i wont to get familiar with gradle plugins, i would like to put this into my own plugin. How is the best way from within a plugin to find out if the build is running in contoinous mode; i.e. i only want to run the clear-screen in case we are running with -t parameter. in normal mode, i dont wan the clearing of the screen.

thanks,
daniel

You can determine if Gradle was started in continuous mode using gradle.startParameter.continuous. When you wrap this in a plugin, you will just need to add project in front of a few lines that were implicitly delegating to project.

class ContinuousClearPlugin implements Plugin<Project> {
    void apply(Project project) {

        if (project.gradle.startParameter.continuous) {

            project.gradle.addListener new BuildAdapter() {
                void projectsEvaluated(Gradle gradle) {
                    project.exec { commandLine 'clear' }
                }
            }

        }

    }
}
1 Like

thanks! esentially, you have written the plugin: https://plugins.gradle.org/plugin/de.dplatz.clear

cheers,
Daniel