Getting Gradle error output

Answered

Hi,

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? 

Thanks,

Dan 

9 comments
Comment actions Permalink
Official comment

Hi,

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

public class GradleTaskNotificationListener extends ExternalSystemTaskNotificationListenerAdapter {
@Override
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;
// ...
}
}
}

 

Comment actions Permalink

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

// run time error

project.getMessageBus().connect().subscribe(RunContentManager.Topic.....) 

// compilation error

project.getMessageBus().connect().subscribe(CompilerTopics.COMPILATION_STATUS.....)

Is this correct?  

0
Comment actions Permalink

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

0
Comment actions Permalink

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? 

0
Comment actions Permalink

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? 

0
Comment actions Permalink

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 :) 

0
Comment actions Permalink

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)

0
Comment actions Permalink

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! 

0
Comment actions Permalink

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 (https://www.jetbrains.com/help/idea/2016.3/runner.html)

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.

0

Please sign in to leave a comment.