3

What is the basic core difference between:

  • kotlin-kapt
  • annotationProcessor()

Also, what's the working behavior of these in Kotlin/Java?

I researched a lot about this topic but I'm a little bit confused. So, I need to learn more to clear my concepts.

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141

1 Answers1

1
  • kapt: Default annotation processor for Kotlin projects, useful to reference generated code at compile time in a kotlin project. In order to use it you should use the kotlin-kapt plugin. It also takes care of java classes
plugins {
    kotlin("kapt") version "1.7.10"
}

and the related dependency:

dependencies {
    kapt("groupId:artifactId:version")
}
  • annotationProcessor: gradle directive to specify your own annotationProcessor or a third party one. For example, in the old android projects was common to use Butterknife library that has its own annotation processor:
dependencies {
  annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.3'
}

In general, an annotation processor is useful to generate code automatically from annotations (for butternife, for example @BindView) and this is true both for kapt and for a random third-party annotation processor.

Nicola Gallazzi
  • 7,897
  • 6
  • 45
  • 64