kapt当一个人有一个 jvm 目标时,可以在 Kotlin Multiplatform 中完成注释处理。
但是,如果没有 jvm 目标,如何处理注释?
具体来说,我想在处理来自commonMain. 但我无法弄清楚如何处理这些。
我的注释处理器此刻只记录:
@SupportedSourceVersion(SourceVersion.RELEASE_8)
@SupportedAnnotationTypes("ch.hippmann.annotation.Register")
@SupportedOptions(RegisterAnnotationProcessor.KAPT_KOTLIN_GENERATED_OPTION_NAME)
class RegisterAnnotationProcessor : AbstractProcessor(){
companion object {
const val KAPT_KOTLIN_GENERATED_OPTION_NAME = "kapt.kotlin.generated"
}
override fun process(annotations: MutableSet<out TypeElement>?, roundEnv: RoundEnvironment?): Boolean {
processingEnv.messager.printMessage(Diagnostic.Kind.WARNING, "Processing")
return true
}
}
Run Code Online (Sandbox Code Playgroud)
注释位于一个单独的多平台模块中,位于commonMain:
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION)
@Retention(AnnotationRetention.RUNTIME)
annotation class Register
Run Code Online (Sandbox Code Playgroud)
并在项目中使用commonMain:
部分build.gradle:
kotlin {
jvm()
// For ARM, should be changed to iosArm32 or iosArm64
// For Linux, should be changed …Run Code Online (Sandbox Code Playgroud) annotations annotation-processing kotlin kapt kotlin-multiplatform