在Kotlin 1.3.30中,添加了对增量注释处理的支持:https://blog.jetbrains.com/kotlin/2019/04/kotlin-1-3-30-released/ 根据文档:
Note that in the current implementation, using any non-incremental annotation processor or a change in dependency’s ABI (so far, including modifying internal declarations) will lead to non-incremental annotation processing for a given module.
我有一个带有多个注释处理器的多模块项目。其中只有一些是增量的。据我所知,至少有一些模块仅使用增量注释处理器。
我的问题是: 有没有办法检查增量注释处理是否发生?例如。 Gradle中是否有任何特定的控制台日志表明这一点?我想确认实际上使用了增量注释处理。
答案 0 :(得分:1)
我能够通过添加来确定
kapt.verbose=true
根项目中gradle.properties
中的。 例如,这导致在控制台中打印以下内容。更改公共方法:
Javac options: {}
[incremental apt] Changed files: [/Users/me/workspace/my-project/core/common/build/tmp/kapt3/stubs/foo/bar/ChangedClassName.java]
...
[INFO] Need to discovery annotation processors in the AP classpath
[INFO] Annotation processors: toothpick.compiler.factory.FactoryProcessor, toothpick.compiler.memberinjector.MemberInjectorProcessor
[INFO] Processing java sources with annotation processors: /Users/me/workspace/my-project/core/common/build/tmp/kapt3/stubs/foo/bar/ChangedClassName.java
[INFO] Annotation processing complete, errors: 0, warnings: 0
[INFO] Annotation processor stats:
[INFO] IncrementalProcessor: total: 61 ms, init: 1 ms, 3 round(s): 59 ms, 0 ms, 1 ms
[INFO] IncrementalProcessor: total: 1 ms, init: 1 ms, 3 round(s): 0 ms, 0 ms, 0 ms
这是使用增量注释处理的时间。 进行干净构建时,将打印:
Javac options: {}
[incremental apt] Changed files: []
...
[INFO] Need to discovery annotation processors in the AP classpath
[INFO] Annotation processors: toothpick.compiler.factory.FactoryProcessor, toothpick.compiler.memberinjector.MemberInjectorProcessor
[INFO] Processing java sources with annotation processors: [ALL THE FILES IN THE MODULE ARE LISTED HERE]
[INFO] Annotation processing complete, errors: 0, warnings: 0
[INFO] Annotation processor stats:
[INFO] IncrementalProcessor: total: 124 ms, init: 1 ms, 3 round(s): 122 ms, 1 ms, 0 ms
[INFO] IncrementalProcessor: total: 1 ms, init: 0 ms, 3 round(s): 1 ms, 0 ms, 0 ms
Toothpick是我正在使用的DI框架,因为2.x支持增量注释处理。
如果有一个不是增量注释的注释处理器,它也会打印例如:
[INFO] Incremental KAPT support is disabled. Processors that are not incremental: butterknife.compiler.ButterKnifeProcessor.