Listen to Gradle build event

Answered

I want to run my plugin once the project (and all it's modules) are compiled. 

connection.subscribe(ProjectTaskListener.TOPIC, object : ProjectTaskListener {})

I used the above and it works when the "Make project" is invoked.

But a Gradle project can be built via the Gradle tool window. When I "build" via the Gradle tool window, the above subscription doesn't get invoked. Is there a way to listen to Gradle tasks? 

Note: I also tried

connection.subscribe(CompilerTopics.COMPILATION_STATUS, object: CompilationStatusListener{})

and it doesn't work as well.

2 comments
Comment actions Permalink

I'm also interested in listening for gradle build events... Can anyone point to right direction?

0
Comment actions Permalink

Hi,

I had some success by subscribing to the following topics:

this.messageBusConnection = project.getMessageBus().connect();
this.messageBusConnection.subscribe(ExecutionManager.EXECUTION_TOPIC, new GradleExecutionListener(this));
this.messageBusConnection.subscribe(ProjectTaskListener.TOPIC, new GradleExecutionListener(this));

and implementing

public class GradleExecutionListener implements ExecutionListener, ProjectTaskListener {
...
}

Not sure yet if this covers all aspects, but maybe you can use this as a starting point for some real work :)

Cheers,
Matthias

 

1

Please sign in to leave a comment.