Execute kapt/kapt2 from within IJ

How can I get the Kotlin annotation processor to run from IJ?

“Enable annotation processors” in Settings does not seem to work.

1 Like

This is currently unsupported. What’s your use case? Why can’t you use Gradle to build your project?

1 Like

Ok thanks. I am using Dagger2. I am using Gradle to build the project (which works fine), however it’s nice when working in the IDE to not switch out of it to do the annotation processing.

What do you mean by “switch out of it”? You can run the Gradle build from within IntelliJ IDEA using the Gradle toolwindow.

Yes of course you’re right. I meant “switch out of it” in terms of task context i.e. IJ just automatically does so much automatically, it feels weird to have to call out to my build (even if from within IJ) to do something.

In any case, I’ve set it up so that the gradle task will run automatically when I do “Rebuild”, which works perfectly well.

1 Like

Are there any plans to implement support for this? We have integrated kapt into our build process, but out of the box, the IntelliJ build system is the default and people expect it to work (it’s also a lot faster, IMO, but that may be an artifact of the old version of gradle we’re stuck on until 1.0.7 or we can upgrade to 1.1). Currently you get missing files and it’s not an intuitive error or cause. In every other area gradle and IJ Build system are equivalent so it seems odd to not have it work for this.


Any progress on this one?
I think it’s really important to have annotation-preprocessing working correctly with Kotlin and required for many of our projects.

Two workarounds for anyone that is affected by this problem: Open Gradle-View and

  • either assign a shortcut for other → kaptKotlin to execute it manually once your Dagger-injections change.
  • or right-click other → kaptKotlin and select Execute Before Build to execute it always.
1 Like

Thanks! This workaround is not a good experience from a dev perspective. Now I have to tell others to enable Execute Before Build or run Gradle build before running the class from IJ.

Please follow the related issue for updates: https://youtrack.jetbrains.com/issue/KT-15040