Hook AnnotationProcessor in Project dynamically


I am trying to write a plugin that can hook into the "annotationProcessor framework" in any given project. Let me explain in detail:

In a gradle project, if we want to add an AnnotationProcessor as a dependency, we will mention the processor in the build.gradle file. I already have a processor bundled with the plugin, and I want to run this as part of the project. I don't want the users to edit their build.gradle file and add the annotation processor as a dependency. Instead, while the project builds, I want the annotation processor in the plugin to run.

So how do I accomplish this? How can I inject my own annotation processor into the project from my plugin?

Comment actions Permalink

How should Gradle know that there is an annotation processor to run if the build.gradle would not be configured accordingly?

Comment actions Permalink

Let's say there are 4 annotation processors configured in build.gradle. So when we build the project, all these 4 annotation processors will run. I wanted to run my own annotation processor along with these 4. My annotation processor is bundled in my plugin. This is what I am trying to accomplish.

I am trying to hook my annotation processor to the existing ones. Is there a way to do this?

Comment actions Permalink

If you add such behavior to your plugin, results of build will differ if run in IDE (with your IDE plugin present) vs run in commandline/CI. So in general it seems more stable to add required steps to build.gradle file directly, together with any required dependencies for running the custom annotation processor.

However, it’s possible to inject such things using Gradle init-scripts, see org.jetbrains.plugins.gradle.service.project.GradleProjectResolverExtension#enhanceTaskProcessing




Please sign in to leave a comment.