Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make custom task who returns boolean in Gradle

Tags:

gradle

build

task

I want to ask how I can make a custom task in gradle for continious build, which do something and returns boolean

class MyTask extends DefaultTask {
    @InputFile
    File first

    @InputFile
    File second

    @TaskAction
    boolean check() {
        return ..
    }
}

So when I call my task in the build script I want to check if the return value is true or false and to do something. Is this poslible to be done and if yes how if not how to do it another way?

task myCheckTAsk(type: MyTask) {
    ...???
}

I want to put my logic in separate groovy class because my build.gradle file will become very long and hard to read.

like image 943
Xelian Avatar asked Jul 04 '13 18:07

Xelian


1 Answers

Task actions can't return a value, but they can assign a value to a property of the task, and later tasks can read that value. Note that you should never call a task action yourself; it's up to Gradle to do so.

like image 175
Peter Niederwieser Avatar answered Sep 29 '22 04:09

Peter Niederwieser