Gradle task that depends on a failure -


can gradle task depend on failure of task?

for example, have auxillary task opens test report in browser. want report appear when task "test" fails, not when tests pass now.

task viewtestreport(dependson: 'test') << {     def testreport = project.testreportdir.tostring() + "/index.html"     "powershell ii \"$testreport\"".execute() } 

you can try set task's finilizedby property, like:

task taskx << {     throw new gradleexception('this task fails!'); }  task tasky << {     if (taskx.state.failure != null) {         //here shoud executed if taskx fails         println 'taskx failed!'     } }  taskx.finalizedby tasky 

you can find explanation gradle's user guide in chapter 14.11 "finalizer tasks". shortly, due docs:

finalizer tasks executed if finalized task fails.

so, have check state of finilized task taskstate , if failed, wanted.

update: unfortunately, because configuration executed tasks, seems not possible create custom task set flag show report within script. on execution phase not possible too, because task not called if previewsly runned task has failed. can do, wanted, providing build script arguments, like:

task viewtestreport << {     if (project.hasproperty("showreport") && test.state.failure != null) {         //here shoud executed on taskx fail         println 'test failed!'     } } test.finalizedby(viewtestreport) 

in case, have provide -pshowreport arguments, while call gradle task, if ou want report in test task fail. example, if call:

gradle test -pshowreport 

then report shown if test task fails, if call it:

gradle test 

no report shown in case.


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -