代码之家  ›  专栏  ›  技术社区  ›  prom85

在kotlin中使用注释处理器

  •  0
  • prom85  · 技术社区  · 6 年前

    import java.lang.annotation.ElementType;
    import java.lang.annotation.Retention;
    import java.lang.annotation.RetentionPolicy;
    import java.lang.annotation.Target;
    
    @Target(ElementType.TYPE) @Retention(RetentionPolicy.CLASS)
    public @interface BundleBuilder
    {
        // ...
    }
    

    这可以在java文件中使用,但只要我将文件转换为kotlin,注释的导入就不再有效了。为什么?

    enter image description here

    我需要做什么改变才能让他的注释在kotlin也能工作?从文档中,我可以看到kotlin与java注释100%兼容,所以我有点搞不清楚问题出在哪里。。。如果处理器不工作,需要调整以与kotlin一起工作,我会理解,但我不知道为什么导入本身不工作。。。

    我说的图书馆在这里: https://github.com/MFlisar/BundleArgs

    1 回复  |  直到 5 年前
        1
  •  2
  •   aminography    6 年前

    我想你应该用 kapt 用于在 build.gradle

    apply plugin: 'kotlin-android-extensions'
    apply plugin: 'kotlin-kapt'
    
    //...
    
    dependencies {
        compileOnly 'com.github.MFlisar.BundleArgs:bundleargs-annotation:1.3'
        kapt 'com.github.MFlisar.BundleArgs:bundleargs-processor:1.3'
    }
    
    repositories {
        maven { url "https://jitpack.io" }
    }