Getting Gradle error output



So my question is how do I get the error message output for Gradle on IntelliJ? 

I know that for Java, we can subscribe a message bus to different topics. 

Is there such thing for Gradle, where I can subscribe to a compilation

or run-time topic and get the errors? 



Official comment


The extension point you need is "com.intellij.externalSystemTaskNotificationListener" (interface com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotificationListener). E.g.

public class GradleTaskNotificationListener extends ExternalSystemTaskNotificationListenerAdapter {
public void onFailure(@NotNull ExternalSystemTaskId id, @NotNull Exception e) {
if (GradleConstants.SYSTEM_ID.getId().equals(id.getProjectSystemId().getId())
&& id.getType() == ExternalSystemTaskType.EXECUTE_TASK) {
final Project project = id.findProject();
if (project == null) return;
// ...


Oh I see. So the // ... part might look like:

// run time error


// compilation error


Is this correct?  


Why? You already have an exception from gradle here, see (@NotNull Exception e)


Wait, so Exception e contains the compilation and run time error of my project?

So for example, if I got a Java.Nullpointer exception, will the exception from gradle

contain the exception for my project? If so, how do I get the exception? 


Maybe this might clear things up.  Does Exception e contains the stderr and stdout from Gradle, where stderr and stdout are

compilation errors produced by Gradle? 


Oh wait, I see what's going on. Within Exception e, I can get the error message from Gradle.

Let me give this a try and I will let you know if I have any more questions.

Thanks for your help :) 


This Exception contains error message of rootCause of exception thrown by gradle tooling api.

To get stderr/stdout you can use another method of the same listener:

com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotificationListener#onTaskOutput(@NotNull ExternalSystemTaskId id, @NotNull String text, boolean stdOut)


Oh I see. 

So my other question is, if I want this plugin to work for Android Studio, meaning that whenever

I press build on Android Studio my plugin will be able to get the gradle output,

will doing it as you suggested work for Android Studio? Much appreciated! 


It will work if you run Gradle Run Configuration both in IntelliJ and Android Studio.

Also it will work if you press build in IntelliJ using "Delegate IDE build/run actions to Gradle" option (

But I'm afraid, if you press build in Android Studio it probably will not work. At least in the code (of android plugin) I do not see if gradle events will be propagated to ExternalSystemProgressNotificationManager. I'm not sure if it was omitted intentionally but it's better to ask in AOSP issue tracker if you need the feature.


Please sign in to leave a comment.