简体   繁体   English

“kotlin-kapt”与“annotationProcessor()”?

[英]"kotlin-kapt" vs "annotationProcessor()"?

What is the basic core difference between:之间的基本核心区别是什么:

  • kotlin-kapt
  • annotationProcessor()

Also, what's the working behavior of these in Kotlin/Java ?另外,这些在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.所以,我需要更多地了解我的概念。

  • kapt : Default annotation processor for Kotlin projects, useful to reference generated code at compile time in a kotlin project. kapt :Kotlin 项目的默认注释处理器,用于在kotlin项目中在编译时引用生成的代码。 In order to use it you should use the kotlin-kapt plugin.为了使用它,您应该使用kotlin-kapt插件。 It also takes care of java classes它还负责 java 类
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. annotationProcessor : gradle 指令指定您自己的 annotationProcessor 或第三方。 For example, in the old android projects was common to use Butterknife library that has its own annotation processor:例如,在旧的 android 项目中,通常使用具有自己的注释处理器的 Butterknife 库:
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.一般来说, annotation processor可用于从注解自动生成代码(对于 butternife,例如@BindView ),这对于 kapt 和随机第三方注解处理器都是如此。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM