Copy Task: How to fail on NO-SOURCE?

plugins

(Markus Perndorfer) #1

I try to find way to configure a copy task in my plugin so that it fails during the execution phase when there are no inputs available.

A few stackoverflow posts mentioned using getInputs().getSourceFiles().stopExecutionIfEmpty(), but I cannot call that while setting the task up in my Plugin.apply() method because this is called during the configuration phase.

doFirst / doLast don’t seem to be executed because of the NO-SOURCE status…

Any ideas?


(Markus Perndorfer) #2

To answer my own question: you can use stopExecutionIfEmpty in onlyIf, as it is still called even if there are no sources available.

I wonder if there is a better way…


(René Groeschke) #3

alternatively you can do

gradle.taskGraph.afterTask { tsk ->
    if(tsk.state.noSource){
        throw new GradleException("stopping build because NO_SOURCE task outcome detected for   
                   ${tsk.path}")
    }
}

in your build script