Hook into Gradle build in Android Studio
I want to run some code each time a Gradle build is initialized by either the user or Android Studio. I have tried two different ways of doing this and neither work. Here is my code:
public class PrivacyAnnotationValidator implements StartupActivity {
public void runActivity(@NotNull Project project) {
System.out.println("We are printing during the project start!");
BuildManagerListener listener = new BuildManagerListener() {
@Override
public void beforeBuildProcessStarted(@NotNull Project project, @NotNull UUID id) {
System.out.println("before it builds");
}
@Override
public void buildStarted(@NotNull Project project, @NotNull UUID sessionId, boolean isAutomake) {
System.out.println("build process initiated!");
}
};
//MessageBus bus = project.getMessageBus();
MessageBus bus = ApplicationManager.getApplication().getMessageBus();
bus.connect().subscribe(BuildManagerListener.TOPIC, listener);
CompilerManager.getInstance(project).addBeforeTask(new PrivacyCompilationTask());
System.out.println("--------------------------");
}
}
At no point does anything ever get printed. PrivacyCompilationTask is literally just a System.out.println statement in the execute method.
Any ideas? Thanks!
Please sign in to leave a comment.
I think that API is for IntelliJ builds.
Most Gradle implementation in IntelliJ is handled through the ExternalSystem API, which I think is where you should look.
I glanced around and couldn't find an extension point that looked right, but you might have more luck looking there.