Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle: custom message on task failure?

Tags:

gradle

I'd like to hook into the compileJava target and spit out an additional custom message on failure. We've got a really common case setup case that a lot of folks overlook and it'd be useful, only on failure, to be able to do something like:

compileJava.onFailure { 
   println "Did you configure your wampfrankle to talk to the slackometer?" 
}

My Google skills have not yet led to an answer.

like image 502
Chris Kessel Avatar asked Feb 17 '14 21:02

Chris Kessel


1 Answers

The error is a dependency error and as Rene points out that needs to be detected after the build has executed, not after the project has been evaluated.

Here I've added a call to buildFinished with a closure that detects if a failure has happened and prints out an error message.

project.gradle.buildFinished { buildResult ->
  if (buildResult.getFailure() != null) {
    println "Did you configure your wampfrankle to talk to the slackometer?" 
  }
}

To test this I force a dependency resolution failure with this bogus dependency:

dependencies {
  compile 'foo:bar:baz'
}
like image 80
ditkin Avatar answered Oct 09 '22 17:10

ditkin